環境:Linux version 2.6.32-642.el6.x86_64 軟體版本:postgresql-9.6.8.tar.gz 下載地址: https://www.postgresql.org/ftp/source/v9.6.8/ 新項目要上線測試,要求安裝一個PG 的資料庫 我們進行的是源 ...
環境:Linux version 2.6.32-642.el6.x86_64 軟體版本:postgresql-9.6.8.tar.gz 下載地址: https://www.postgresql.org/ftp/source/v9.6.8/
新項目要上線測試,要求安裝一個PG 的資料庫
我們進行的是源碼包的安裝
1:下載源碼包
2:安裝資料庫需要的依賴包
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
3:解壓源碼包
[root@oracle soft]# tar -xvf postgresql-9.6.8.tar.gz
4:創建 需要的目錄
[root@oracle soft]# mkdir postgres
[root@oracle soft]# mkdir pgsql
5:進入解壓後的目錄
[root@oracle soft]# cd postgresql-9.6.8
6:開始編譯安裝PostgreSQL 資料庫
[root@oracle postgresql-9.6.8]# ./configure --prefix=/data/soft/postgres
7:執行gmake
8:執行gmake install
9:創建postgresql 的數據目錄
[root@oracle soft]# mkdir pgsql
[root@oracle ~]# groupadd postgres
[root@oracle ~]# useradd -g postgres postgres
[root@oracle soft]# chown postgres:postgres /data/soft/postgres -R
[root@oracle soft]# chown postgres:postgres /data/soft/pgsql -R
[root@oracle soft]# chmod 700 /data/soft/pgsql -R
10:配置環境變數
[postgres@oracle ~]$ cat .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export PATH=/data/soft/postgresql/bin:$PATH
export PGDATA=/data/soft/pgsql
11:初始化資料庫 指定數據目錄
[postgres@oracle ~]$ /data/soft/postgres/bin/initdb -D /data/soft/pgsql/
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /data/soft/pgsql ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/data/soft/postgres/bin/pg_ctl -D /data/soft/pgsql/ -l logfile start
12:啟動數資料庫
[postgres@oracle ~]$ /data/soft/postgres/bin/pg_ctl start
server starting
[postgres@oracle ~]$ LOG: database system was shut down at 2018-05-22 15:11:11 CST
LOG: MultiXact member wraparound protections are now enabled
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
13:創建資料庫
[postgres@oracle ~]$ psql
-bash: psql: command not found
如果報上面的錯誤說明你的你的程式的路徑不在path變數中,用絕對路徑調用下你的psql看看
postgres=# create user lhh with login password 'm2i3sc@newnet';
^
postgres=# grant all privileges on database nntlds to lhh;
我們還可以導入數據到指定的資料庫
[postgres@kvm-openAPI ~]$ psql -U postgres -W -d nntlds -f /data/public.sql
到這一個postgresql 資料庫就算搭建完成了。