Back to Postgres Language Server

Rules

docs/reference/rules.md

0.24.04.7 KB
Original Source

Rules

Below the list of rules supported by the Postgres Language Server, divided by group. Here's a legend of the emojis:

  • The icon ✅ indicates that the rule is part of the recommended rules.

Safety

Rules that detect potential safety issues in your code.

Rule nameDescriptionProperties
addSerialColumnAdding a column with a SERIAL type or GENERATED ALWAYS AS ... STORED causes a full table rewrite.
addingFieldWithDefaultAdding a column with a DEFAULT value may lead to a table rewrite while holding an ACCESS EXCLUSIVE lock.
addingForeignKeyConstraintAdding a foreign key constraint requires a table scan and a SHARE ROW EXCLUSIVE lock on both tables, which blocks writes.
addingNotNullFieldSetting a column NOT NULL blocks reads while the table is scanned.
addingPrimaryKeyConstraintAdding a primary key constraint results in locks and table rewrites.
addingRequiredFieldAdding a new column that is NOT NULL and has no default value to an existing table effectively makes it required.
banCharFieldUsing CHAR(n) or CHARACTER(n) types is discouraged.
banConcurrentIndexCreationInTransactionConcurrent index creation is not allowed within a transaction.
banDropColumnDropping a column may break existing clients.
banDropDatabaseDropping a database may break existing clients (and everything else, really).
banDropNotNullDropping a NOT NULL constraint may break existing clients.
banDropTableDropping a table may break existing clients.
banTruncateCascadeUsing TRUNCATE's CASCADE option will truncate any tables that are also foreign-keyed to the specified tables.
changingColumnTypeChanging a column type may break existing clients.
constraintMissingNotValidAdding constraints without NOT VALID blocks all reads and writes.
creatingEnumCreating enum types is not recommended for new applications.
disallowUniqueConstraintDisallow adding a UNIQUE constraint without using an existing index.
lockTimeoutWarningTaking a dangerous lock without setting a lock timeout can cause indefinite blocking.
multipleAlterTableMultiple ALTER TABLE statements on the same table should be combined into a single statement.
preferBigIntPrefer BIGINT over smaller integer types.
preferBigintOverIntPrefer BIGINT over INT/INTEGER types.
preferBigintOverSmallintPrefer BIGINT over SMALLINT types.
preferIdentityPrefer using IDENTITY columns over serial columns.
preferJsonbPrefer JSONB over JSON types.
preferRobustStmtsPrefer statements with guards for robustness in migrations.
preferTextFieldPrefer using TEXT over VARCHAR(n) types.
preferTimestamptzPrefer TIMESTAMPTZ over TIMESTAMP types.
renamingColumnRenaming columns may break existing queries and application code.
renamingTableRenaming tables may break existing queries and application code.
requireConcurrentIndexCreationCreating indexes non-concurrently can lock the table for writes.
requireConcurrentIndexDeletionDropping indexes non-concurrently can lock the table for reads.
runningStatementWhileHoldingAccessExclusiveRunning additional statements while holding an ACCESS EXCLUSIVE lock blocks all table access.
transactionNestingDetects problematic transaction nesting that could lead to unexpected behavior.