postgresql学习笔记一之安装
Yum安装postgresql yum 安装 如果是默认yum安装的话,会安装较低版本的PostgreSQL8.4。 我们使用PostgreSQLYum Repository 来安装最新版本的PostgreSQL。
[root@tigase3~]# rpm -i http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpm 1.1 安装新版本PostgreSQL [root@tigase3~]# yum install postgresql92-server postgresql92-contrib 1.2 查看安装 [root@tigase3 ~]# rpm-qa | grep postgresql postgresql92-9.2.8-1PGDG.rhel6.x86_64 postgresql92-server-9.2.8-1PGDG.rhel6.x86_64 postgresql92-libs-9.2.8-1PGDG.rhel6.x86_64 postgresql92-contrib-9.2.8-1PGDG.rhel6.x86_64 2.初始化并启动数据库 [root@tigase3~]# /etc/init.d/postgresql-9.2 initdb Initializingdatabase: [ OK ] 3.启动数据库并测试 [root@tigase3~]# chkconfig postgresql-9.2 on [root@tigase3~]# service postgresql-9.2 start Startingpostgresql-9.2 service: [ OK ] [root@tigase3~]# su ? postgres #切到postgres用户 -bash-4.1$psql psql(9.2.8) Type"help" for help. postgres=# 在未设置第7步pg_hba.conf时只能切换到postgres登录,更改为以下后,可以直接在root下psql -U postgres local all all trust 4.设置postgresql数据库超级用户的密码,默认超级用户为postgres,默认密码为空,设定超级用户密码为postgres. postgres=#ALTER USER postgres WITH PASSWORD 'postgres'; ALTERROLE 5、创建一个用户tigase,密码为tigase.同时创建一个数据库tigasedb,simkai;">数据库的所有者为tigase. postgres=#create user tigase with password 'tigase'; CREATEROLE postgres=#create database tigasedb with owner tigase; CREATEDATABASE postgres=#l #使用l列出所建数据库及所有者 Listof databases Name | Owner | Encoding | Collate | Ctype | Accessprivileg es tigasedb | tigase | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres=#q #q退出 -bash-4.1$ 6、修改PostgresSQL数据库配置实现远程访问。 -bash-4.1$vi /var/lib/pgsql/9.2/data/postgresql.conf #listen_addresses= ‘localhost’ 改为:listen_addresses= '*' #监听整个网络 7、修改客户端认证配置文件pg_hba.conf,将需要远程访问数据库的IP地址或地址段加入该文件。 -bash-4.1$vi /var/lib/pgsql/9.2/data/pg_hba.conf #IPv4 local connections:
local all all trust host all all 127.0.0.1/32 trust host all all 192.168.3.0/24 trust 添加远程访问数据库的IP网段为trust,simkai;">如果为MD5;访问数据库时需要输入密码。 8、重启服务,测试连接数据库。 [root@tigase3~]# service postgresql-9.2 restart Stoppingpostgresql-9.2 service: [ OK ] Startingpostgresql-9.2 service: [ OK ] [root@tigase3~]# psql -U postgres或su ? postgres #用户 -bash-4.1$psql -h 127.0.0.1 -U tigase -W -d tigasedb # -W强行要求用户输入密码 Passwordfor user tigase: psql(9.2.8) Type"help" for help. tigasedb=> #已进入tigasedb数据库,可使用dt、d查询表和表结构,没有数据会显示关系不能找到。 以下为安装tigase服务器时的表操作 更改数据库表的所有者。 -bash-4.1$psql -h 127.0.0.1 -U postgres -W -d tigasedb #进入超级用户更改tigasedb Passwordfor user postgres: tigasedb=# tigasedb=#alter table short_news owner to tigase; #更改表short_news的所有者为ALTERTABLE tigasedb=#dt Schema| Name | Type | Owner --------+--------------------------+-------+---------- public| short_news | table | tigase public| tig_nodes | table | postgres (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |