1.切换用户
[root@master scripts]# su - postgres
-bash-4.1
2.登陆postpostgresql控制台
-bash-4.1$ psql
postgres=#
3. 进入ambari库
postgres=# \c ambari
ambari=#
4.授予ambari用户对ambari库的权限
ambari=# grant postgres to ambari;
GRANT ROLE
ambari=# grant all privileges on database ambari to ambari;
GRANT
5.退出
ambari=# \q
6.重新使用amabri用户进入postgresql(默认密码bigdata)
[root@master scripts]# su - postgres
-bash-4.1$ psql -U ambari
Password for user ambari:
psql (8.4.20)
Type "help" for help.
ambari=>
7.列举数据库
ambari=> \l
8.列举表
ambari=> \dt
9.查看表结构
ambari=> \d users
10.Select查询
ambari=> select * from host_version;
11.切换数据库
ambari=>\c dbName