postgresql 安装 – knowledge「建议收藏」

postgresql 安装 – knowledge「建议收藏」参考:https://www.postgresql.org/docs/current/install-procedure.html 完事开头难!!!如果想了解一门技术,看文档必不可少,实操更不可少,这

postgresql 安装 - knowledge

参考: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.gz
tar zxvf /usr/local/src/postgresql-10.5.tar.gz -C /usr/local
ln -s /usr/local/postgresql-10.5 /usr/local/pgsql

代码100分

  

2、创建用户和目录并授权

 

代码100分useradd postgresql
echo "123456" | passwd --stdin postgresql
mkdir -pv /dbdata/pgsql10.5/pg5432/data
chown postgresql:postgresql /usr/local/pgsql
chown postgresql:postgresql /dbdata/pgsql10.5/pg5432/data

 

3、用户postgresql配置环境变量

 

export PGHOME=/usr/local/pgsql
export PGDATA=/dbdata/pgsql10.5/pg5432/data
export PGUSER=postgresql
LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:/usr/include
export LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH

 

4、编译并安装

 

代码100分cd /usr/local/pgsql
./configure --prefix=/usr/local/pgsql  --with-pgport=5432
gmake
gmake world
gmake install
gmake 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=C
The 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 ... 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:

    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]$ psql
psql: FATAL:  database "postgresql" does not exist

登录pg数据库的时候如果不指定-d参数默认就会找跟当前操作系统用户同名的database


[postgresql@lxdnode2 data]$ psql -d postgres -U admin
psql (10.5)
Type "help" for help.

postgres=# 

这里留下一个伏笔,如果刚刚接触pg的同学可能会好奇,明明设置了admin用户的密码了,为什么登录的时候没有要求密码验证就可以登录进去呢?

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/10199.html

(0)
上一篇 2023-01-23
下一篇 2023-01-23

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注