千家信息网

Linux下PostgreSQL如何源码安装

发表于:2025-02-04 作者:千家信息网编辑
千家信息网最后更新 2025年02月04日,这篇文章将为大家详细讲解有关Linux下PostgreSQL如何源码安装,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。1、首先安装依赖包,避免在安装过程中出现问题s
千家信息网最后更新 2025年02月04日Linux下PostgreSQL如何源码安装

这篇文章将为大家详细讲解有关Linux下PostgreSQL如何源码安装,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

1、首先安装依赖包,避免在安装过程中出现问题

shell> yum install gcc gcc-c++ automake autoconf libtool makeshell> yum install readline-develshell> yum install zlib-devel

2、创建postgre用户及用户组

shell> groupadd postgreshell> useradd -g postgre postgre   shell> passwd postgre                #修改密码shell> id postgreuid=500(postgre) gid=501(postgre) 组=501(postgre)

3、编译安装postgre

shell> tar zxvf postgresql-9.3.6.tar.gzshell> cd postgresql-9.3.6shell> ./configure --prefix=/db/pgsqlshell> make && make install  PostgreSQL installation complete.

4、设置数据库目录权限并初始化数据库

shell> mkdir -p /db/pgsql/datashell> chown -R postgre.postgre /db/pgsql/shell> cp contrib/start-scripts/linux /etc/rc.d/init.d/postgresqlshell> su - postgre# 初始化数据库shell> /db/pgsql/bin/initdb -D /db/pgsql/data/The files belonging to this database system will be owned by user "postgre".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.fixing permissions on existing directory /db/pgsql/data ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBcreating configuration files ... okcreating template1 database in /db/pgsql/data/base/1 ... okinitializing pg_authid ... okinitializing dependencies ... okcreating system views ... okloading system objects' descriptions ... okcreating collations ... okcreating conversions ... okcreating dictionaries ... oksetting privileges on built-in objects ... okcreating information schema ... okloading PL/pgSQL server-side language ... okvacuuming database template1 ... okcopying template1 to template0 ... okcopying template1 to postgres ... oksyncing data to disk ... okWARNING: enabling "trust" authentication for local connectionsYou 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:    /db/pgsql/bin/postgres -D /db/pgsql/data/or    /db/pgsql/bin/pg_ctl -D /db/pgsql/data/ -l logfile start

5、设置环境变量

shell> vi .bash_profile==================================================================PATH=$PATH:$HOME/bin:/db/pgsql/binexport PGDATA=/db/pgsql/dataexport PGHOME=/db/pgsqlexport LANG=zh_CN.UTF-8export PGPORT=5432export PATH==================================================================shell> source .bash_profile

6、开启postgre服务

shell> pg_ctl -D /db/pgsql/data/ -l /db/pgsql/log/logfile start server startingshell> tail -f /db/pgsql/logfileLOG:  database system was shut down at 2015-04-20 17:59:36 CSTLOG:  database system is ready to accept connectionsLOG:  autovacuum launcher started

7、测试连接数据库

shell> createdb mydbshell> psql -h 127.0.0.1 -p 5432 -U postgre -W mydbPassword for user postgre: psql (9.3.6)Type "help" for help.mydb=# # 显示当前数据库mydb=# \l                                List of databases   Name    |  Owner  | Encoding |   Collate   |    Ctype    |  Access privileges  -----------+---------+----------+-------------+-------------+--------------------- mydb      | postgre | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 |  postgres  | postgre | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 |  template0 | postgre | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgre         +           |         |          |             |             | postgre=CTc/postgre template1 | postgre | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgre         +           |         |          |             |             | postgre=CTc/postgre(4 rows)# 退出命令行mydb=# \q

关于"Linux下PostgreSQL如何源码安装"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

0