Size: 3756
Comment:
|
Size: 3989
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. It runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages). It includes most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP. It also supports storage of binary large objects, including pictures, sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others, and exceptional documentation. | PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. It runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages). It includes most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP. It also supports storage of binary large objects, including pictures, sounds, or video. It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others, and exceptional documentation. |
Line 12: | Line 18: |
* yum install postgresql * yum install postgresql-devel * yum install postgresql-server * service postgresql initdb * chkconfig postgresql on * service postgresql start |
{{{#!highlight sh yum install postgresql yum install postgresql-devel yum install postgresql-server service postgresql initdb chkconfig postgresql on service postgresql start }}} |
Line 20: | Line 28: |
* local all all ident * host all all 0.0.0.0/0 password |
{{{#!highlight sh local all all ident host all all 0.0.0.0/0 password }}} |
Line 24: | Line 33: |
* service postgresql restart | {{{#!highlight sh service postgresql restart }}} |
Line 32: | Line 43: |
* su postgres * psql * create user appuser with login password '12345678'; * create database app; * grant all privileges on database app to appuser; * \q |
{{{#!highlight sh su postgres psql }}} {{{#!highlight sql create user appuser with login password '12345678'; create database app; grant all privileges on database app to appuser; \q }}} |
Line 41: | Line 57: |
* listen-address="*" * port = 5432 * max_connections = 100 |
{{{ listen-address="*" port = 5432 max_connections = 100 }}} |
Line 46: | Line 63: |
* service postgresql restart | {{{#!highlight sh service postgresql restart }}} |
Line 49: | Line 68: |
{{{#!highlight sh | |
Line 50: | Line 70: |
}}} | |
Line 52: | Line 73: |
* su postgres * pg_dump databasex > /var/lib/pgsql/backDatabasex.sql * psql databasex < /var/lib/pgsql/backDatabasex.sql # restore |
{{{#!highlight sh su postgres pg_dump databasex > /var/lib/pgsql/backDatabasex.sql psql databasex < /var/lib/pgsql/backDatabasex.sql # restore }}} |
Line 73: | Line 96: |
* su postgres * \c databasex * \dt * \d+ tablex |
{{{#!highlight sh su postgres \c databasex \dt \d+ tablex }}} |
Line 79: | Line 104: |
* su postgres * \c databasex * alter table tablex drop column columnx; |
{{{#!highlight sh su postgres }}} {{{#!highlight sql \c databasex alter table tablex drop column columnx; }}} |
Line 104: | Line 133: |
* apt install postgresql-11 * netstat -at -n | grep 5432 * ss -a -n | grep 5432 |
{{{#!highlight sh apt install postgresql-11 netstat -at -n | grep 5432 ss -a -n | grep 5432 }}} |
Line 109: | Line 140: |
* ALTER USER appuser WITH SUPERUSER; * ALTER USER appuser WITH NOSUPERUSER; |
{{{#!highlight sql ALTER USER appuser WITH SUPERUSER; ALTER USER appuser WITH NOSUPERUSER; }}} |
Postgresql
PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness.
It runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris, Tru64), and Windows. It is fully ACID compliant, has full support for foreign keys, joins, views, triggers, and stored procedures (in multiple languages).
It includes most SQL:2008 data types, including INTEGER, NUMERIC, BOOLEAN, CHAR, VARCHAR, DATE, INTERVAL, and TIMESTAMP. It also supports storage of binary large objects, including pictures, sounds, or video.
It has native programming interfaces for C/C++, Java, .Net, Perl, Python, Ruby, Tcl, ODBC, among others, and exceptional documentation.
http://www.postgresql.org/about/
Install Postgresql on CentOS 6.4
These installation steps should also apply to other distros based on RedHat source RPMs.
Logged in as root on the system run the following commands:
Edit the file /var/lib/pgsql/data/pg_hba.conf
To restart the postgresl DB run the command:
1 service postgresql restart
Check postgresql version
1 cat /var/lib/pgsql/data/PG_VERSION
Create postgresql test user and database
Configure postgresql to accept all TCP connections
Edit the file /var/lib/pgsql/data(postgresql.conf
listen-address="*" port = 5432 max_connections = 100
Restart again the postgresl DB:
1 service postgresql restart
Test the connection using the user and password
1 psql -U appuser -h 127.0.0.1 -W -d a++
Backup and restore with pg_dump
Daily backup script
1 #!/bin/sh
2 #backupDBs.sh
3 #chmod 755 backupDBs.sh
4 #backup database postgresql
5 #crontab -e
6 #@daily /var/lib/pgsql/backupDBs.sh
7 BACKUPFOLDER=/var/lib/pgsql/backups
8 CURRDATE=`date -u "+%Y-%m-%dT%H:%m:%S.%Z"`
9 FILE=$BACKUPFOLDER/backup$CURRDATE.sql
10 DATABASE=dbx
11 /usr/bin/pg_dump $DATABASE > $FILE
12 gzip $FILE
Show table structure
Drop a table column
1 su postgres
Epoch from date field
Number of seconds since 1st January 1970 UTC.
Garbage-collect and analyze a PostgreSQL database
Create file /var/lib/pgsql/vacuumdb.sh and chmod 755 it
Create cron job to user postgres, crontab -e
@daily /var/lib/pgsql/vacuumdb.sh
Install in debian buster
Give super user rights to user
List databases
- su postgres
- psql
- postgres=# \l