源码安装postgresql9.5.1
前端之家收集整理的这篇文章主要介绍了
源码安装postgresql9.5.1,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
一.下载
在官网下载软件,我选择的是最新的版本进行安装postgresql95,地址如下:
下载源码.tar.gz的软件包
二.进行解压缩
[root@pg1 soft]# tar zxvf postgresql-9.5.1.tar.gz ..........postgresql1/docsrcsgmlproblemssgmlarch-devpageinspectinfoinstallationxplang/MakefileKNOWN_BUGSTODOMISSING_FEATURESbugtemplateHISTORYREADMECOPYRIGHT/GNUmakefile.in/.gitattributesaclocalm4configureINSTALL
三.开始安装
进入解压缩的目录,可以执行./configure --help查看配置选项,--prefix指定安装目录,因为我最近在学习python,所以我把python
插件也安装上了
root@pg1 postgre
sql ./configure --prefix=/usr/localpgsql95 withpythonchecking build system type... x86_64pclinuxgnuchecking host system typechecking which template to use linuxchecking whether to build with 64bit integer datetime support yeschecking whether NLS is wanted nochecking for default port number 5432 block size8kB segment size1GB WAL block size8kB......
安装使用gmake world 和gmake install-world,带上world关键字会把一些第三方的
插件也安装上,建议带上world,如果一开始没有安装上,可以手工在解压缩目录下的contrib目录下执行make&&make install
gmake world
&& gmake installworldgmake[2]: Leaving directory `/root/soft/postgresql-9.5.1/contrib/unaccent'gmake -C vacuumlo installgmake[2]: Entering directory `rootsoftcontribvacuumlo'/bin/mkdir -p 'pgsql95bin/usr/bin/install -c vacuumlo 'gmake[2]: Leaving directory `/root/soft/postgresql-9.5.1/contrib/vacuumlo'gmake C hstore_plpython install Entering`/root/soft/postgresql-9.5.1/contrib/hstore_plpython'/bin/mkdir -p '/usr/local/pgsql95/lib'/bin/mkdir -p '/usr/local/pgsql95/share/extension'/usr/bin/install -c -m 755 hstore_plpython2.so '/usr/local/pgsql95/lib/hstore_plpython2.so'/usr/bin/install -c -m 644 ./hstore_plpythonu.control ./hstore_plpython2u.control ./hstore_plpython3u.control '/usr/local/pgsql95/share/extension/'/usr/bin/install -c -m 644 ./hstore_plpythonu--1.0.sql ./hstore_plpython2u--1.0.sql ./hstore_plpython3u--1.0.sql '/usr/local/pgsql95/share/extension/'gmake[2]: Leaving directory `hstore_plpythongmake -C ltree_plpython installgmake[2]: Entering directory `/root/soft/postgresql-9.5.1/contrib/ltree_plpython'binmkdir p '/usr/local/pgsql95/lib''/usr/local/pgsql95/share/extension'install c m 755 ltree_plpython2so '/usr/local/pgsql95/lib/ltree_plpython2.so'644ltree_plpythonucontrol ltree_plpython2ultree_plpython3ucontrol '/usr/local/pgsql95/share/extension/'--1.0sql sql '/usr/local/pgsql95/share/extension/'`/root/soft/postgresql-9.5.1/contrib/ltree_plpython'gmake[1]: Leaving directory `contribPostgresql,contrib,and documentation installation complete.
root@pg1 lib useradd postgres
修改postgres
用户的环境变量,并且记得将pg的数据目录所属改成postgres
export PGPORT=export PGDATApgdataexport LANG=en_USexport PGHOMEpgsql95export LD_LIBRARY_PATH$PGHOMElib:$LD_LIBRARY_PATHexport PATH$PATH$HOMEbinexport MANPATHshareman$MANPATHexport PGUSERpostgres
使用postgres
用户登录系统,查看环境变量是否正确,输入p
sql -V查看pg的版本
使用initdb来初始化
数据库,可以使用initdb --help查看选项
initdb -D $PGDATA -E UTF8 --locale=C -U postgres -W
其中-D指定数据目录,-E指定字符集,-locale指定区域,-U指定
用户,-W指定密码,在初始化的时候会让你输入密码
$ initdb
D $PGDATA E UTF8 localeC U postgres WThe 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 "C" default text search configuration will be set to "english".Data page checksums are disabledfixing permissions on existing directory pgdata initdb could not change permissions of directory "/pgdata" Operation not permitted$ id postgresuid500(postgres gid groups) okcreating subdirectories selecting default max_connections 100selecting default shared_buffers 128MBselecting dynamic shared memory implementation posixcreating configuration files creating template1 database pgdatabase/1initializing pg_authid okEnter new superuser password Enter it again setting password initializing dependencies creating system views loading 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: pg_ctl -D /pgdata -l logfile start
进入到初始化指定的数据
文件目录,就可以看到pg的目录结构
root@pg1
su postgresls$ ls$ cd postgres@pg1 pgdata]$ ls ltotal 112drwx------.5 postgres postgres 4096 Feb2420:39 base2 global pg_clog pg_commit_ts pg_dynshmemrw-------.4468 pg_hbaconf1636 pg_identconf4 pg_logical pg_multixact pg_notify pg_replslot pg_serial pg_snapshots pg_stat pg_stat_tmp pg_subtrans pg_tblspc pg_twophase PG_VERSION3 pg_xlog88 postgresqlauto21673conf
base目录:表空间目录
pg_hba.conf:访问控制配置
pg_hba.conf用于配置控制访问
数据库的来源
像oracle一样,最好也调整一下linux内核参数,
添加sysctl.conf
文件的配置
-9.5.1 sysctl -p
vi etcsysctlconf kernelshmmax 68719476736shmall 4294967296shmmni sem 50100641280001280fsfilemax 7672460netipv4ip_local_port_range 900065000corermem_default 1048576rmem_max 4194304wmem_default 262144wmem_max 1048576
同样配置limits.conf
securitylimits* soft nofile 131072 hard nofile soft nproc hard nproc soft core unlimited hard core unlimited soft memlock 50000000 hard memlock 50000000
配置pg_hba.conf,默认是只允许本地访问pg,
添加如下允许所有的ip访问所有的database
host all all 0.0.0.0/0 md5
配置postgre
sql.conf,最简单的配置需要配置监听端口号和ip地址如下:
listen_addresses '*' # what IP address(es) to listen on;# comma-separated list of addresses;# defaults to 'localhost'; use '*' for all# (change requires restart)port # (change requires restart)
使用pg_ctl start启动数据,如果一开始初始化的时候没有指定数据
文件位置,启动需要指定数据
文件位置
pg_ctl start -D $PGDATA
$ pg_ctl startserver starting$ LOG database system was shut down at 2016023935 CSTLOG MultiXact member wraparound protections are now enabled database system is ready to accept connections autovacuum launcher started
$ p
sql()Type"help" help.postgres=# \db List of tablespaces Name | Owner | Location ------------+----------+---------- pg_default | postgres | pg_global | postgres | (2 rows) postgres=# \q $
停止 pg使用:
pg_ctl stop -m fast或者指定数据
文件位置:
pg_ctl stop -D $PGDATA -m fast
停止选项有三种分别为:fast,smart,immediate
其中fast类似于oracle中的immediate
smart类似于oracle中的normal
immediate类似于oracle中的abort
原文链接:https://www.f2er.com/postgresql/194655.html