In addition to what others have said, Postgres does not have the concept of a "clustered index" like Microsoft SQL Server and other databases. You can cluster the index, but this is a one-time operation (until you call it again) and it will not support row clustering when editing, etc. See documents
. I came across the same thing as you, where I half expected the rows to be returned in the order of the primary key (although I did not insert them out of order, like you did, though). They returned after the initial insertion, but editing a post in Postgres seems to move the post to the end of the page, and the posts are out of order (I updated fields other than the primary key).
source share