Overview
5 Improper feature usage
Unidirectional logical replication
Logical replication in both directions
Summary
-
SQL_ASCIIis not a character encoding so much as the absence of one. If you don’t want to risk mixing encodings irreversibly and you enjoy the ease of automatic character set conversion, make sure you use UTF-8 for your database. - PostgreSQL
RULEs are not related to rules as defined in other DBMSs.RULEs are complicated to understand and are mainly there as Postgres internal machinery. In most cases they don’t behave as the user expects them to andTRIGGERs are best used instead. - Using JSON(B) values with relational access patterns makes for less efficient SQL which is harder to read and might not perform as well. It’s better not to mix the SQL and NoSQL paradigms, but use each facility for what it’s best at doing.
-
uuids take up more storage space than evenbigints and indexing them is less efficient. They may guarantee a range of values that you simply don’t require for your use case, and an integer index might be enough to guarantee uniqueness. - Bi-directional or multi-master replication is more complex than what appears at first sight. For practical use in a production system, there is a very long list of prerequisites, considerations and caveats. If your use case indeed justifies setting up a multi-master system, you are better off using an established multi-master solution whose developers have given thought to these issues rather than re-inventing the wheel.
- All of the above apply to homemade distributed systems as well and it is not recommended to set out building them unless your scope is very narrowly focused. You need to consider the potential for distributed serialization anomalies and the very real trade-offs laid out in the CAP and PACELC theorems.
FAQ
What is SQL_ASCII in PostgreSQL and why is it risky?
SQL_ASCII isn’t a real encoding. PostgreSQL treats bytes 0–127 as ASCII and leaves 128–255 uninterpreted. That means no validation and no server-side conversion. You can silently mix multiple encodings in the same column and later be unable to decode them reliably. Use UTF8 unless you must interoperate with a known legacy encoding.How do I migrate a legacy SQL_ASCII database to UTF-8?
- Create a new UTF8 database with proper locale: CREATE DATABASE ... ENCODING UTF8 LC_COLLATE '...UTF-8' LC_CTYPE '...UTF-8' TEMPLATE template0.- For each text column, convert bytes using the true source encoding, for example: convert_from(convert(col::bytea, 'ISO-8859-1','UTF8'),'UTF8').
- Export/import or INSERT...SELECT into the new DB.
- Set client_encoding correctly and verify collations.
PostgreSQL Mistakes and How to Avoid Them ebook for free