Linux环境Postgresql10源码安装
1.下载安装包
wget 压缩包网址是:https://www.postgresql.org/ftp/source/
从这里选择需要的版本下载即可
2.解压缩
tar -xvf postgresql-10.tar.gz
3. 编译
3.1 cd到 解压缩后的目录
./configure --help 可以查看./configure 后跟的参数代表什么意思
我的安装目录是:
./configure --prefix=/usr/local/pgsql
gmake
显示:All of PostgreSQL successfully made. Ready to install.就可以install了
bash-4.2$ gmake
......
......
gmake -C config all
gmake[1]: Entering directory `/home/postgres/postgres-10/config'
gmake[1]: Nothing to be done for `all'.
gmake[1]: Leaving directory `/home/postgres/postgres-10/config'
All of PostgreSQL successfully made. Ready to install.
gmake install
bash-4.2$ gmake install
...
...
gmake[1]: 进入目录“/home/postgres/postgres-10/config”
/bin/mkdir -p '/usr/local/pg10/lib/postgresql/pgxs/config'
/bin/install -c -m 755 ./install-sh '/usr/local/pg10/lib/postgresql/pgxs/config/install-sh'
/bin/install -c -m 755 ./missing '/usr/local/pg10/lib/postgresql/pgxs/config/missing'
gmake[1]: 离开目录“/root/postgres10/postgres-10/config”
PostgreSQL installation complete.
PostgreSQL installation complete.说明安装成功
3.2查看数据库版本
install成功了,我们来看下数据库版本:
bash-4.2$ /usr/local/pg10/bin/postgres --version
postgres (PostgreSQL) 10.0
4.修改安装目录的所属用户为postgres
chown -R postgres:postgres /usr/local/pg10/
5.初始化数据目录
创建一个用户为postgres的数据目录,权限为0700
chmod -R 0700 /home/postgres/pg10/data
切换用户为postgres用户。
su - postgres
这样的操作是非常有必要的,因为当初始化数据库的时候,执行命令的用户成为数据库的所有者,服务器进程也将被该用户所拥有。
-bash-4.2$ /usr/local/pg10/bin/initdb -D /home/postgres/pg10/data -W
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 "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".
Data page checksums are disabled.
Enter new superuser password:
Enter it again:
fixing permissions on existing directory /home/postgres/pg10/data ... 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:
/usr/local/pg10/bin/pg_ctl -D /home/postgres/pg10/data -l logfile start
6.启动数据库
可以按照上一步中给出的启动方式进行启动:
-bash-4.2$ /usr/local/pg10/bin/pg_ctl -D /home/postgres/pg10/data -l logfile start
waiting for server to start.... done
server started
查看数据库进程是否存在,可以用ps -ef | grep postgres
也可以用查看端口的方式来检查,postgresql默认端口号是5432:
7.配置环境变量
vi ~/.bash_profile
export PATH=/usr/local/pg10/bin:$PATH
export PGDATA=/home/postgres/pg10/data
export LD_LIBRARY_PATH=/usr/lib:/usr/local/pg10/lib:/usr/local/lib
source ~/.bash_profile
配好环境变量之后,下次再启动数据库服务就不用加绝对路径了,可以直接
pg_ctl start 启动。
8. 改数据库配置参数
1.postgresql.conf
vi /usr/local/pgsql/data/postgresql.conf
listen_addresses=’*’;
post=5432
2.pg_hba.conf
vi /usr/local/pgsql/data/pg_hba.conf
在文件最后一行加上:
增加 host all all 0.0.0.0/0 md5
即可。
9.配好环境变量,启动数据库服务后可以用\psql 切到数据库中,如果要切换到linux
环境用 \q即可。