Postgresql – Tips and Trics

Login:

$ psql <dbname> -U <user_name>

After login at Postgresql Console:

  •  Exit:
    • dbname=# q
  • List all tables:
    • dbname=# dt
  • Info about specific table
    • dbname=# d+ <table_name>

List all rows where column value is null

  • perspectivedb=# select * from cluster_config_property where key is null;

Deleting all rows where column value is null:

  • perspectivedb=# delete from cluster_config_property where key is null;

Backing up a single table:

  • This is done from regular prompt (not when you are logged into psql)
  • $ pg_dump -t <table_name> <db_name> -U <user_name> > <target_file_name>.sql

Restoring a single table back into database:

Advertisements