Common PostgreSQL patterns - Dump and restore

 

 

SQL Materialized views

 

Regular Views:

Materialized Views:

https://www.postgresql.org/docs/current/rules-materializedviews.html

 

SQL admin queries

 

image-20230519162355428

 

https://www.alibabacloud.com/help/en/analyticdb-for-postgresql/latest/use-pg-stat-activity-to-analyze-and-diagnose-active-sql-queries

 

 

Database location

 

 

SQL queries

Arrays and tuples

 

 

 

Group by day

 

 

 

Avoid inserting twice if cannot use unique index (is_deleted case)

image-20220124153459594

Access SQL via console

 

Rename table

 

 

Dump and restore - SQL

https://www.postgresql.org/docs/9.3/app-pgdump.html

pg_dump additional useful flags

Binary dump

 

Delete

 

Login as sudo

Switch database

List constraints and triggers of table