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

cdh PostgreSQL

发布时间:2020-12-13 17:09:30 所属栏目:百科 来源:网络整理
导读:centos用yum安装postgresql的路径为 /var/lib/pgsql/中。 1.安装postgresql9.0 yum 仓库 rpm -i http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-redhat92-9.2-7.noarch.rpm 2.安装新版本的Postgresql yum install postgresql92-server postgresql

centos用yum安装postgresql的路径为 /var/lib/pgsql/中。

1.安装postgresql9.0 yum 仓库

rpm -i http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-redhat92-9.2-7.noarch.rpm

2.安装新版本的Postgresql

yum install postgresql92-server postgresql92-contrib

3.初始化数据库

/etc/init.d/postgresql-9.2 initdb

4.启动数据库

/etc/init.d/postgresql-9.2 start

注意:postgresql启动后就可以利用service postgresql-9.2 start/restart/stop来控制它了。
虽然打完service后,按p不提示postgresql-9.2,但是可以用手输。

5.把postgresql加入自启动列表

cd /etc/init.d
chkconfig –add postgresql9.2

6.查看一下自启动列表

chkconfig –list

在这里可以看到postgresql已经在其中了。

7.PostgreSQL 数据库默认会创建一个postgres的数据库用户作为数据库的管理员,默认密码为空,我们需要修改为指定的密码,这里设定为’postgres’

直接在控制台输入以下命令:

# su - postgres
$ psql
#CREATE USER amon WITH PASSWORD 'fuzegame';
#CREATE DATABASE amon OWNER amon;
#GRANT ALL PRIVILEGES ON DATABASE amon to amon;
#l 
显示数据库
# c amon 
进入数据库
#d 
查看所有表
#amon =# create table test (id integer,name text);
#amon =# insert into test values (1,'david');

至上,安装成功。


ps:1.可以通过查找pg_hba.conf,来定位postgresql的位置。
2.重启postgresql,可以用service postgresql restart

第一种方法,使用PostgreSQL控制台。
首先,新建一个Linux新用户,可以取你想要的名字,这里为dbuser。
sudo adduser dbuser
然后,切换到postgres用户。
sudo su - postgres
下一步,使用psql命令登录PostgreSQL控制台。
psql
这时相当于系统用户postgres以同名数据库用户的身份,登录数据库,这是不用输入密码的。如果一切正常,系统提示符会变为”postgres=#”,表示这时已经进入了数据库控制台。以下的命令都在控制台内完成。
第一件事是使用password命令,为postgres用户设置一个密码。
password postgres
第二件事是创建数据库用户dbuser(刚才创建的是Linux系统用户),并设置密码。
CREATE USER dbuser WITH PASSWORD ‘password’;
第三件事是创建用户数据库,这里为exampledb,并指定所有者为dbuser。
CREATE DATABASE exampledb OWNER dbuser;
第四件事是将exampledb数据库的所有权限都赋予dbuser,否则dbuser只能登录控制台,没有任何数据库操作权限。
GRANT ALL PRIVILEGES ON DATABASE exampledb to dbuser;
最后,使用q命令退出控制台(也可以直接按ctrl+D)。
q

问题1:
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
解决办法:Edit /var/lib/pgsql/data/postgresql.conf file
Change
#listen_addresses = ‘localhost’
to
listen_addresses = ‘*’

问题2:
org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host “”,user “fkong”,database “fkong”,SSL off
解决办法:
Edit /var/lib/pgsql/data/pg_hba.conf file
Add below line under “# IPv4 local connections:”
“host all all /32 password”

问题3: org.postgresql.util.PSQLException: FATAL: Ident authentication failed for user “fkong” 解决办法: Edit /var/lib/pgsql/data/pg_hba.conf file Change “host all all /32 ident” to “host all all /32 password”

(编辑:李大同)

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

    推荐文章
      热点阅读