Environment description
System: CentOS 6.4 64-bit
Software: PostgreSQL 9.4.1
Software downloads
cd/usr/local/src/
wget https://ftp.postgresql.org/pub/source/v9.4.1/postgresql-9.4.1.tar.gz
Install Dependency Pack
Yum install-y perl-extutils-embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel Python-devel gcc-c++ Openssl-devel CMake
Install PostgreSQL
Tar XF postgresql-9.4.1.tar.gz
CD postgresql-9.4.1
./configure--prefix=/usr/local/pgsql--with-perl--with-python--with-libxml--with-libxslt
Gamke
Gamke Install
Installing the PG Plugin
Cd/usr/local/src/postgresql-9.4.1/contrib
Gmake
Gmake Install
Load Dynamic Libraries
echo "/usr/local/pgsql/lib" >>/etc/ld.so.conf.d/pgsql.conf
Ldconfig
Initializing the database
Create User Postgres
Useradd Postgres
echo "Postgres" |passwd--stdin postgres
Create PG Data Directory
Mkdir-p/data/pg/data
Chown-r POSTGRES:POSTGRES/DATA/PG
/usr/local/pgsql/bin/initdb--no-locale-u postgres-e utf8-d/data/pg/data-w
(at the time of initialization, look at the prompts to add a Superuser's password)
Note
initdb [Options] ... [DataDir]
-A, default authentication method for--auth=method local connection
-D,--pgdata=datadir the current database cluster location
-E,--encoding=encoding sets the default encoding for the new database
--locale=locale Set the default locale for the new database
--lc-collate,--lc-ctype,--lc-messages=locale
--lc-monetary,--lc-numeric,--lc-time=locale
To separate the new database clusters in their respective directories
Setting the default locale (default use environment change
Amount
--no-locale equal to--locale=c
--pwfile= filename to read password from file for new super User
-T,--text-search-config=cfg
Default Text Search Configuration
-U,--username=name database Super User name
-W,--pwprompt Enter password for new super user prompt
-X,--xlogdir=xlogdir the location of the current transaction log directory
Non-common usage options:
-D,--debug produces a lot of debugging information
The location of the-l DIRECTORY input file
-N,--noclean not cleaned up after an error
-S,--show display internal settings
Other options:
-?,--Help displays this assistance, and then exits
-V,--version output version information, and then exit
If no data directory is specified, the environment variable is used Pgdata
Configure run environment variables (easy to manage)
Switch to Root
Vim/etc/profile
Add the following code:
Pgdata=/data/pg/data
pghost=127.0.0.1
Pgdatabase=postgres
Pguser=postgres
pgport=5432
Path=/usr/local/pgsql/bin: $PATH
Export PATH
Export Pgdata PGHOST pgdatabase pguser pgport
Implementation effective
Source/etc/profile
PostgreSQL Service Management
Start:
Pg_ctl start-d/data/pg/data
Reboot:
Pg_ctl restart-d/data/pg/data
Stop it:
Pg_ctl stop-d/data/pg/data
Force reboot:
Pg_ctl restart-d/data/pg/data-m F
Force stop:
Pg_ctl stop-d/data/pg/data-m F
-M-f specifies fast shutdown
Load configuration:
Pg_ctl reload-d/data/pg/data
Show Service Status:
Pg_ctl status-d/data/pg/data
Connecting to a database
Psql-h 127.0.0.1-u postgres-p 5432-d postgres-w
-D Specify the database,-W Enter the password,-u Specify the user,-p specifies the port,-h specifies the IP
Copy PostgreSQL Execute script
Cp/usr/local/src/postgresql-9.4.1/contrib/start-scripts/linux/etc/init.d/postgresql
chmod +x/etc/init.d/postgresql
Modify/etc/init.d/postgresql
Change the pgdata into Pgdata=/data/pg/data
Join power-on Boot
Chkconfig PostgreSQL on
You can also use the above boot script directly when managing the PG service
Start: Service PostgreSQL start
STOP: Service PostgreSQL stop
Restart: Service PostgreSQL restart
Loading: Service PostgreSQL Reload
Status: Serivce PostgreSQL status