Skip to content

Tags

On this page

Postgresql Tips

0. Enter psql

psql

Show all databases

\l

Enter Database

\c database_name

Show all Tables

\d

Show Table structure

\d table_name

Pretty print table

\x on

Alter table

See https://www.postgresql.org/docs/current/sql-altertable.html

Upsert

See https://stackoverflow.com/questions/61494958/postgres-on-conflict-do-update-only-non-null-values-in-python

Export Schema

pg_dump database_name -s --no-owner > schema.sql

Export Only data

pg_dump database_name -a --no-owner > data.sql

Delete or Drop or Remove Database

psql
drop database database_name;

Create Database

psql
CREATE DATABASE name;

Import Database

psql database_name < data.sql
Edit this page
Last updated on 1/25/2022