Hello World from OSS Silicon Valley


HowToUse/PostgreSQL/9.2

_ Prerequisite

  • Amazon Linux installation

_ Install&Setup

_ Amazon Linux

Step.1
Install PostgreSQL.
$ sudo yum install postgresql postgresql-server postgresql-contrib pgadmin3
Step.2
Set up the initial password for postgres user.
$ sudo passwd postgres
<password>
Step.3
Initialize DB
$ sudo service postgresql initdb
$ sudo /etc/rc.d/init.d/postgresql start
$ sudo chkconfig postgresql on
Step.4
Setup the initial password for postgres DB user.
$ su - postgres
$ psql
postgres=# alter user postgres with password '<password>';
Step.4
Launch pgAdminIII.
Install_fig1.png
Install_fig2.png
Step.5
Access DB.
Install_fig3.png
Install_fig4.png

_ HowToUse

_ HowToUse

_ Connect Database

Step.1
Execute the following command.
$ psql -U <User Name> -d <Database Name>

example)

$ psql -U postgres -d sample_development

_ Fundamental commands

(Get User list)

# select * from pg_user;

(Get Database list)

# \l

or

# select * from pg_database;

(Get Table list)

# \d

or

# select * from pg_class;

(Get Table Columns)

# \d <table name>

_ Backup & Restore Database

_ SQL dump

Step.1
Backup database with the following command.
$ pg_dump <Database Name> -U <User Name> > <Dump File Name>
Step.2
Restore database with the following command.
$ drop database <Database Name>
$ create database <Database Name>
$ psql <Database Name> < <Dump File Name>

_ File Level Backup

Backup PGDATA directory. In general it is /var/lib/psql/data, but my case is /var/lib/postgresql/9.3/main.

$ tar -cf <backup file name> <PGDATA directory path>

(Example)

$ tar -cf backup.tar /var/lib/psql/data

_ Author

S.Yatsuzuka

 
Attach file: fileInstall_fig4.png 180 download [Information] fileInstall_fig3.png 176 download [Information] fileInstall_fig1.png 147 download [Information] fileInstall_fig2.png 138 download [Information]
Last-modified: 2016-06-27 (Mon) 02:55:57 (2857d)