postgrepsql安装入门

我的系统版本

[root@www ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core)

可以yum吗

[root@www ~]# yum list | grep postgresql
postgresql-libs.x86_64                     9.2.23-3.el7_4              @updates   
postgresql-contrib.x86_64                  9.2.23-3.el7_4              updates  
postgresql-devel.i686                      9.2.23-3.el7_4              updates  
………………  
 ………………相关等等

可以

[root@www ~]# yum install -y postgresql
[root@www ~]# rpm -ql postgresql   你会找不到配置文件,配置文件不在/etc/下面
……………………
/usr/share/pgsql/tsearch_data/ispell_sample.dict
/usr/share/pgsql/tsearch_data/spanish.stop
/usr/share/pgsql/tsearch_data/unaccent.rules
/usr/share/pgsql/tsearch_data/xsyn_sample.rules
/var/lib/pgsql/backups
………………………………
/var/lib/pgsql/data
/var/run/postgresql
[root@www ~]# cd /var/lib/pgsql/
[root@www pgsql]# ls
backups  data
[root@www pgsql]# ls data/   配置文件应该在这里
[root@www pgsql]# 


初始化数据库

[root@www ~]# which postgresql-setup
/usr/bin/postgresql-setup
[root@www ~]# postgresql-setup initdbInitializing database ... OK
[root@www ~]# ls /var/lib/pgsql/ 对比初始化前生成了initdb.log文件[root@www ~]# ls /var/lib/pgsql/data 生成好多文件包括配置文件

启动数据库

[root@www ~]# systemctl start postgresql

在安装过程中自动生成了postgres用户,切到此用户下

[root@www ~]# su postgres
bash-4.2$ psql
could not change directory to "/root"
psql (9.2.23)
Type "help" for help.

postgres=# 


报错:could not change directory to "/root"
解决
:目录权限的问题

      找到问题:

postgres=# \q
bash-4.2$ su root
Password: 
[root@www ~]# ll /var/lib/pgsql
total 8
drwx------.  2 postgres postgres    6 Dec  8 11:52 backups
drwx------. 15 postgres postgres 4096 Dec 19 01:09 data
-rw-------.  1 postgres postgres 1266 Dec 19 01:06 initdb.log
[root@www ~]# ll /usr/share/pgsql
total 924
drwxr-xr-x. 2 root root      6 Dec  8 11:52 contrib
-rw-r--r--. 1 root root  74932 Dec  8 11:52 conversion_create.sql
drwxr-xr-x. 2 root root     89 Dec 19 00:52 extension
-rw-r--r--. 1 root root 106304 Dec  8 11:52 information_schema.sql
-rw-r--r--. 1 root root   4420 Dec  8 11:52 pg_hba.conf.sample
-rw-r--r--. 1 root root   1636 Dec  8 11:52 pg_ident.conf.sample
-rw-r--r--. 1 root root    604 Dec  8 11:52 pg_service.conf.sample
-rw-r--r--. 1 root root 519298 Dec  8 11:52 postgres.bki
-rw-r--r--. 1 root root  98569 Dec  8 11:52 postgres.description
-rw-r--r--. 1 root root  19793 Dec  8 11:52 postgresql.conf.sample
-rw-r--r--. 1 root root     49 Dec  8 11:52 postgres.shdescription
-rw-r--r--. 1 root root    278 Dec  8 11:52 psqlrc.sample
-rw-r--r--. 1 root root   4704 Dec  8 11:52 recovery.conf.sample
-rw-r--r--. 1 root root  13337 Dec  8 11:52 snowball_create.sql
-rw-r--r--. 1 root root  33035 Dec  8 11:52 sql_features.txt
-rw-r--r--. 1 root root  27557 Dec  8 11:52 system_views.sql
drwxr-xr-x. 2 root root    237 Dec 19 00:52 timezonesets
drwxr-xr-x. 2 root root   4096 Dec 19 00:52 tsearch_data
[root@www ~]# 

     解决:
[root@www ~]# chown postgres:postgres  /usr/share/pgsql
再次查看,就ok了
[root@www ~]# su postgres
bash-4.2$ psql
could not change directory to "/root"
psql (9.2.23)
Type "help" for help.

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(3 rows)

postgres=# 





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值