Random unguessable primary key which preserves correct order I want primary keys in my table to be random and unguessable while still preserving correct order (order in which documents were inserted to database). Firebase uses this algorithm: https://gist.github.com/mikelehen/3596a30bd69384624c11. Is it a good idea to port it to psql or plv8 for example and use in postgres to generate primary keys for a table? Or maybe there is other solution out of the box in PG?
Don't do that.  

If you want to make a user-unique-and-crazy-key don't use the primary key of the table, create another column with this kind of data and you can generate a unique code using md5 of the unix microtime for example.

The Human world are strange for databases, believe me or not! Let the keys to be keys, its nice and faster to table relationships.

And for any user or system search you use another column, its very like to want to relationship users by using a person one identification code, so you change the country and discovery the code repeats, and all your database is lost. You want a unique crazy code, but it does not mean nothing for your machine, how your machine will work for nothing to make your relationships working. For relationships use things that your machine can really understand, in another words: Use sequential numbers.