Postgres Schema

Simple tutorial to show some command that let you operate with your postgreSQL and schema.

Connect to your database.

Let’s say 10.10.10.10 is your postgres host.

psql -h 10.XX.XX.185 -U postgres

List databases

\l

Every schema were attached with a database, now connect to the database.

\c [database_name]

List all schema tables

\dt *.*

List particular schema tables

\dt scheduler.*

Describe table

\d [schema].[table_name]

Sample alter command

ALTER TABLE [schema].[column] ALTER COLUMN [column_name] TYPE text;

 

Backup command

./pg_dump -h {db-host} -U {username} {database} -f {path_to_backup.sql}

Eg:

./pg_dump -h x.x.x.xxx -U postgres -d mydatabase -f mydatabase.sql

 

Restore command

./psql -h {db-host} -U {username} -d {database}  -f {path_to_backup.sql}

Eg:

./psql -U postgres -d mydatabase -f  /Users/mingch/Documents/mydatabase.sql

 

 

Postgres Schema

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.