加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql安装完成后的操作

发布时间:2020-12-13 17:20:29 所属栏目:百科 来源:网络整理
导读:1. 修改数据库的postgres账号的密码 1) su - postgres ( 以 postgres 账号登录 ) 2) psql -p 5433 (如果监听端口不是默认的5432,那么要加上-p参数) 3) ALTER USER postgres WITH PASSWORD 'password' ; ( 修改 postgres 账号的密码为password ) 4) q (退出

1. 修改数据库的postgres账号的密码

1) su - postgres (postgres账号登录)

2) psql -p 5433 (如果监听端口不是默认的5432,那么要加上-p参数)

3) ALTER USER postgres WITH PASSWORD 'password';(修改postgres账号的密码为password)

4) q (退出psql客户端)

说明:PostgreSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码是随机的,需要修改为指定的密码。

2. 修改linux系统用户postgres的密码,密码与上一步相同。

1) passwd -d postgres (删除原密码)

2) passwd postgres

3. 修改postgresql配置文件实现远程访问

1) vim /path/to/postgresql.conf

#listen_addresses= ‘localhost’改为listen_addresses = ‘*’

#password_encryption= on改为password_encryption = on

2) 修改可访问的用户ip段

vim /path/to/pg_hba.conf

在文档末尾加上以下内容:

#to allow your client visiting postgresql server

host all user 192.168.100.101/32 md5

注意:一定要把/var/lib/pgsql/9.3/data/pg_hba.conf

local all all这行的最后改为trust

其它所有行都改为md5

4. 重启postgresql

service postgresql-9.3 restart

5. 修改/root/.bash_profile

PATH=$PATH:$HOME/bin:/usr/pgsql-9.3/bin

使其生效:source /root/.bash_profile

6. 登录数据库

su - postgres

/usr/pgsql-9.3/bin/psql

7. 创建用户user,但是不给其创建数据库的权限

postgres=#create user $user with password‘password';

postgres=#alter user $user createdb; #使用户具有创建数据库的权限

postgres=#select * from pg_user; #查看用户权限

8. 创建数据库db,指定其所有者为$user

postgres=#create database db with owner=user;

j) 尝试从本机连接数据库

psql -p 5433 -U user -h 127.0.0.1 -ddb -W (一定要-W才会提示输入密码)

j) 尝试从另一台主机连接数据库

psql -p 5433 -U user -h 192.168.1.xxx -d db -W (一定要-W才会提示输入密码)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读