본문 바로가기
DevOps 잡다구리/DevOps Tools

[Postgresql] Using postgresql for development and pg_dump

by WhiteGoblin 2024. 2. 20.
반응형

 

 Usually accessing to database is not recommended, but when developing a program we usually make an dummy database and access to the database directly.

 

 So I am going to post some command which are helpful when you need to access the develop database directly.

1. you will be needing psql cmd to access the postgresql database, in mac book you can use the below command. 

 

brew install postgresql

 

if you are using other kind of OS please check the below URL.

 

https://www.postgresql.org/download/

 

PostgreSQL: Downloads

 

www.postgresql.org

 

2. After you have installed the command line you just need to login to the database using the command line. 

 

psql -h [HOSTNAME] -p [PORT] -d [DATABASE_NAME] -U [USERNAME]

 

3. Now you will probably entered the database now if you do not have any information just use the below command to list all the database.

 

\l

 

4. Now you know the databases just use the below command to list the tables.

\dt

 

 

5. if you want more information about tables detail use the below command.

 

\d [TABLE_NAME]

 

 

6. if you want to go out you can just use \q  to quit.


7. And last but not least if you planning to dump the postgresql db you can use pg_dump 

pg_dump -h [HOST] -p [PORT] -U [USERNAME] -d [DATABASE_NAME] -f [DUMPFILE_NAME]

 

The postgresql will require you to enter in the password. 

8. And you can restore it easily by 

psql -h [HOSTNAME] -p [PORT] -d [DATABASE] -U [USERNAME] -f [BACKUP_FILE_NAME]

 

now you have back up the postgresql database : ) 

 

it just for develop server, when you are tending to use production you should be using other stuffs.

반응형