Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 35810)
+++ src/wp-includes/post.php	(working copy)
@@ -3583,16 +3583,22 @@
 			$slug = $alt_post_name;
 		}
 	} elseif ( is_post_type_hierarchical( $post_type ) ) {
+		// Nav menu items don't need unique post slugs because they don't have rewrites.
 		if ( 'nav_menu_item' == $post_type )
 			return $slug;
 
 		/*
-		 * Page slugs must be unique within their own trees. Pages are in a separate
-		 * namespace than posts so page slugs are allowed to overlap post slugs.
+		 * Ensure the entire URL path is unique, respective of potentially conflicting
+		 * post type paths.
 		 */
-		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
-		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
-
+		if( '/%postname%/' === $wp_rewrite->permalink_structure && $post_parent === 0 ) {
+			// If posts share the same permalink structure with pages, also check posts for uniqueness.
+			$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'post', 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
+			$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
+		} else {
+			$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
+			$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
+		}
 		/**
 		 * Filter whether the post slug would make a bad hierarchical post slug.
 		 *
@@ -3613,9 +3619,15 @@
 			$slug = $alt_post_name;
 		}
 	} else {
-		// Post slugs must be unique across all posts.
-		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
-		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
+		// Post slugs of a non-hierarchical post-type must be unique to one another.
+		if ( '/%postname%/' == $wp_rewrite->permalink_structure && 'post' === $post_type ) {
+			// Avoid collisions between post and page slugs.
+			$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'page' ) AND ID != %d LIMIT 1";
+			$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
+		} else {
+			$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
+			$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID ) );
+		}
 
 		// Prevent new post slugs that could result in URLs that conflict with date archives.
 		$post = get_post( $post_ID );
Index: tests/phpunit/tests/post.php
===================================================================
--- tests/phpunit/tests/post.php	(revision 35810)
+++ tests/phpunit/tests/post.php	(working copy)
@@ -1253,4 +1253,83 @@
 		$this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date);
 		$this->assertEquals($post['post_date_gmt'], $out->post_date_gmt);
 	}
+
+	function test_unique_slug_page_then_post() {
+		global $wp_rewrite;
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$page_args = array(
+			'post_type' => 'page',
+			'post_name' => 'green',
+			'post_status' => 'publish',
+		);
+		$page = $this->factory->post->create( $page_args );
+		$this->assertEquals( 'green', get_post( $page )->post_name );
+
+		$post_args = array(
+			'post_type' => 'post',
+			'post_name' => 'green',
+			'post_status' => 'publish',
+		);
+		$post = $this->factory->post->create( $post_args );
+
+		$this->assertEquals( 'green-2', get_post( $post )->post_name );
+		$wp_rewrite->flush_rules();
+	}
+
+	function test_unique_slug_post_then_page() {
+		global $wp_rewrite;
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$post_args = array(
+			'post_type' => 'post',
+			'post_name' => 'red'
+		);
+		$post = $this->factory->post->create( $post_args );
+		$this->assertEquals( 'red', get_post( $post )->post_name );
+
+		$page_args = array(
+			'post_type' => 'page',
+			'post_name' => 'red'
+		);
+		$page = $this->factory->post->create( $page_args );
+		$this->assertEquals( 'red-2', get_post( $page )->post_name );
+		$wp_rewrite->flush_rules();
+	}
+
+	function test_unique_slug_post_then_post() {
+		global $wp_rewrite;
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$post_args = array(
+			'post_type' => 'post',
+			'post_name' => 'blue'
+		);
+		$post = $this->factory->post->create( $post_args );
+		$this->assertEquals( 'blue', get_post( $post )->post_name );
+
+		$post_args = array(
+			'post_type' => 'post',
+			'post_name' => 'blue'
+		);
+		$post = $this->factory->post->create( $post_args );
+		$this->assertEquals( 'blue-2', get_post( $post )->post_name );
+		$wp_rewrite->flush_rules();
+	}
+
+	function test_unique_slug_page_then_page() {
+		global $wp_rewrite;
+		$wp_rewrite->set_permalink_structure( '/%postname%/' );
+		$page_args = array(
+			'post_type' => 'page',
+			'post_name' => 'orange'
+		);
+		$page = $this->factory->post->create( $page_args );
+		$this->assertEquals( 'orange', get_post( $page )->post_name );
+
+		$page_args = array(
+			'post_type' => 'page',
+			'post_name' => 'orange'
+		);
+		$page = $this->factory->post->create( $page_args );
+		$this->assertEquals( 'orange-2', get_post( $page )->post_name );
+		$wp_rewrite->flush_rules();
+	}
 }
