postgres 数据库的安装
postgres 数据库的安装
环境:Linux version 2.6.32-642.el6.x86_64 软件版本:postgresql-9.6.8.tar.gz
新项目要上线测试,要求安装一个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;
到这一个postgresql 数据库就算搭建完成了。