postgresql 安装
参考:https://www.postgresql.org/docs/current/install-procedure.html
完事开头难!!!如果想了解一门技术,看文档必不可少,实操更不可少,这篇博文记录了自己学习postgesql的测试安装文档,由于对pg的参数了解甚少,目前使用的默认的参数。
1、下载安装介质、解压并配置软连接
https://www.postgresql.org/download/找到 Source code-> 点击 file browser链接 https://www.postgresql.org/ftp/source/ 选择需要下载的对应版本源码安装介质wget https://ftp.postgresql.org/pub/source/v10.5/postgresql-10.5.tar.gz上传到/usr/local/src/postgresql-10.5.tar.gztar zxvf /usr/local/src/postgresql-10.5.tar.gz -C /usr/localln -s /usr/local/postgresql-10.5 /usr/local/pgsql
2、创建用户和目录并授权
useradd postgresqlecho "123456" | passwd --stdin postgresqlmkdir -pv /dbdata/pgsql10.5/pg5432/datachown postgresql:postgresql /usr/local/pgsqlchown postgresql:postgresql /dbdata/pgsql10.5/pg5432/data
3、用户postgresql配置环境变量
export PGHOME=/usr/local/pgsqlexport PGDATA=/dbdata/pgsql10.5/pg5432/dataexport PGUSER=postgresqlLD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:/usr/includeexport LD_LIBRARY_PATHexport PATH=$PGHOME/bin:$PATH:.export MANPATH=$PGHOME/share/man:$MANPATH
4、编译并安装
cd /usr/local/pgsql./configure --prefix=/usr/local/pgsql --with-pgport=5432gmakegmake worldgmake installgmake install-world说明:/usr/local/pgsql/configure --help | grep size --with-blocksize=BLOCKSIZE set table block size in kB [8] --with-segsize=SEGSIZE set table segment size in GB [1] --with-wal-blocksize=BLOCKSIZE set WAL block size in kB [8] --with-wal-segsize=SEGSIZE set WAL segment size in MB [16]这些参数在编译的时候可以指定,后续初始化后就不可以重新设置了,除非重新安装的时候指定这些参数。
5.初始化
[postgresql@lxdnode2 ~]$ initdb -E UTF8 -D $PGDATA -U admin -W --locale=CThe files belonging to this database system will be owned by user "postgresql".This user must also own the server process.The database cluster will be initialized with locale "C".The default text search configuration will be set to "english".Data page checksums are disabled.Enter new superuser password: Enter it again: fixing permissions on existing directory /dbdata/pgsql10.5/pg5432/data ... okcreating subdirectories ... okselecting default max_connections ... 100selecting default shared_buffers ... 128MBselecting dynamic shared memory implementation ... posixcreating configuration files ... okrunning bootstrap script ... okperforming post-bootstrap initialization ... 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 /dbdata/pgsql10.5/pg5432/data -l logfile start
6.启动数据库
pg_ctl -D /dbdata/pgsql10.5/pg5432/data -l logfile start
7.连接数据库
[postgresql@lxdnode2 data]$ psqlpsql: FATAL: database "postgresql" does not exist登录pg数据库的时候如果不指定-d参数默认就会找跟当前操作系统用户同名的database[postgresql@lxdnode2 data]$ psql -d postgres -U adminpsql (10.5)Type "help" for help.postgres=# 这里留下一个伏笔,如果刚刚接触pg的同学可能会好奇,明明设置了admin用户的密码了,为什么登录的时候没有要求密码验证就可以登录进去呢?
赞 (0)