RHEL7.2+PostgreSQL9.6.1
Requirements softwares
1.GNU make version 3.80 or newer is required
[root@rhel7 ~]# make --version
GNU Make 3.82
Built for x86_64-redhat-linux-gnu
2.You need an ISO/ANSI C compiler (at least C89-compliant). Recent versions of GCC are recommended
[root@rhel7 ~]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4)
3. tar is required to unpack the source distribution, in addition to either gzip or bzip2.
4.The GNU Readline library is used by default.
readline
readline-devel
libedit
Optional
perl 5.8 or later
python
Kerberos
OpenSSL
OpenLDAP
and/or PAM
Flex 2.5.31 or later
Bison 1.875 or later
useradd pguser
su - pguser
tar -zxvf postgresql-9.6.1.tar.gz
Install
cd postgresql-9.6.1
./configure
預設安裝目錄/usr/local/pgsql,可以使用--prefix=path進行修改,./configure --help
make
The last line displayed should be:
All of PostgreSQL successfully made. Ready to install.
su (使用root安裝)
make install
PostgreSQL installation complete.
Set the environment variables for pguser
mkdir /usr/local/pgsql/data #PostgreSQL資料存儲目錄
chown pguser:pguser /usr/local/pgsql/data
export LD_LIBRARY_PATH=/usr/local/pgsql/lib
export PG_HOME=/usr/local/pgsql
export PATH=$PG_HOME/bin/:$PATH
export PGDATA=/usr/local/pgsql/data
Initilize the DBServer
(使用pguser)
<code>[pguser@rhel7 ~]$ initdb -D </code><code>/usr/local/pgsql/data</code>
<code>The files belonging to this database system will be owned by user </code><code>"pguser"</code><code>.</code>
<code>This user must also own the server process.</code>
<code>The database cluster will be initialized with locale </code><code>"en_US.UTF-8"</code><code>.</code>
<code>The default database encoding has accordingly been </code><code>set</code> <code>to </code><code>"UTF8"</code><code>.</code>
<code>The default text search configuration will be </code><code>set</code> <code>to </code><code>"english"</code><code>.</code>
<code>Data page checksums are disabled.</code>
<code>fixing permissions on existing directory </code><code>/usr/local/pgsql/data</code> <code>... ok</code>
<code>creating subdirectories ... ok</code>
<code>selecting default max_connections ... 100</code>
<code>selecting default shared_buffers ... 128MB</code>
<code>selecting dynamic shared memory implementation ... posix</code>
<code>creating configuration files ... ok</code>
<code>running bootstrap script ... ok</code>
<code>performing post-bootstrap initialization ... ok</code>
<code>syncing data to disk ... ok</code>
<code>WARNING: enabling </code><code>"trust"</code> <code>authentication </code><code>for</code> <code>local</code> <code>connections</code>
<code>You can change this by editing pg_hba.conf or using the option -A, or</code>
<code>--auth-</code><code>local</code> <code>and --auth-host, the next </code><code>time</code> <code>you run initdb.</code>
<code>Success. You can now start the database server using:</code>
<code> </code><code>pg_ctl -D </code><code>/usr/local/pgsql/data</code> <code>-l logfile start</code>
Start the DBServer
<code>[pguser@rhel7 ~]$ postgres -D /usr/</code><code>local</code><code>/pgsql/data >logfile 2>&1 &</code>
<code>[1] 13799</code>
<code>[pguser@rhel7 ~]$ ps -ef |grep postgre</code>
<code>pguser 13799 4377 0 12:37 pts/0 00:00:00 postgres -D /usr/</code><code>local</code><code>/pgsql/data</code>
<code>pguser 13801 13799 0 12:37 ? 00:00:00 postgres: checkpointer process </code>
<code>pguser 13802 13799 0 12:37 ? 00:00:00 postgres: writer process </code>
<code>pguser 13803 13799 0 12:37 ? 00:00:00 postgres: wal writer process </code>
<code>pguser 13804 13799 0 12:37 ? 00:00:00 postgres: autovacuum launcher process </code>
<code>pguser 13805 13799 0 12:37 ? 00:00:00 postgres: stats collector process </code>
<code>pguser 13807 4377 0 12:37 pts/0 00:00:00 grep </code><code>--color=auto postgre</code>
連接配接測試
<code>[pguser@rhel7 ~]$ psql </code><code>--list</code>
<code> </code><code>List </code><code>of</code> <code>databases</code>
<code> </code><code>Name</code> <code>| Owner | Encoding | </code><code>Collate</code> <code>| Ctype | Access </code><code>privileges</code>
<code>-----------+--------+----------+-------------+-------------+-------------------</code>
<code> </code><code>postgres | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | </code>
<code> </code><code>template0 | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/pguser +</code>
<code> </code><code>| | | | | pguser=CTc/pguser</code>
<code> </code><code>template1 | pguser | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/pguser +</code>
<code>(3 </code><code>rows</code><code>)</code>
<code>[pguser@rhel7 ~]$ psql postgres</code>
<code>psql (9.6.1)</code>
<code>Type </code><code>"help"</code> <code>for</code> <code>help.</code>
<code>postgres=# </code><code>select</code> <code>version();</code>
<code> </code><code>version </code>
<code>---------------------------------------------------------------------------------------------------------</code>
<code> </code><code>PostgreSQL 9.6.1 </code><code>on</code> <code>x86_64-pc-linux-gnu, compiled </code><code>by</code> <code>gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-4), 64-</code><code>bit</code>
<code>(1 row)</code>
<code>postgres=# </code><code>select</code> <code>current_date</code><code>;</code>
<code> </code><code>date</code>
<code>------------</code>
<code> </code><code>2016-12-01</code>
<code>postgres=# \q</code>
官方文檔:https://www.postgresql.org/docs/9.6/static/installation.html
本文轉自hbxztc 51CTO部落格,原文連結:http://blog.51cto.com/hbxztc/1878425,如需轉載請自行聯系原作者