在虚拟机(centos)配置postgresql数据库(1) - 安装篇
来源:互联网 发布:python 技术指标 编辑:程序博客网 时间:2024/04/30 11:38
一、安装
参考:
http://zhidao.baidu.com/link?url=XZQH28IBTUK--2109zwxNKGoMFfZ_xCYS9VUt8iRX0APcadfTG1OabjSyE0tzO5cxmIcc9td6Jeb9ThaHkMsKa
http://www.linuxidc.com/Linux/2012-02/53982.htm
首先要到下面地址下载源代码自行编译安装。
http://www.postgresql.org/ftp/source/v9.3.3/
我下载了:
postgresql-9.3.3.tar.gz
并且加压缩以后,在当前文件夹下面打开终端,用su换成root权限,然后输入:
# ./configure --prefix=/usr/local/pgsql
出现:
configure: error: readline library not found
这个还真的要安装devel版本的readline才行,解决方案:
yum -y install -y readline-devel
安装这个版本。
然后再输入
# ./configure --prefix=/usr/local/pgsql
结束以后 输入 make,结束以后提示可以安装了,、
输入
# make install
然后安装成功。
二、配置数据库
参考资料:
http://blog.51yip.com/pgsql/1520.html
http://blog.csdn.net/starnight_cbj/article/details/6905985
http://blog.chinaunix.net/uid-25885064-id-3404550.html
postgres数据在linux下面必须用postgres账号才能正常初始化(何解?),所以先添加postgres 用户组及用户,然后添加一个新的data文件(作为数据库文件的存放目录),然后切换至postgres账号初始化数据库。
下面来自:http://blog.sina.com.cn/s/blog_6742dfb7010160w7.html
没有这个文件夹就用root账号新建那个文件夹。
6、创建用户组和用户:
groupadd postgres
useradd -g postgres postgres
7、创建数据库库文件存储目录、给postgres赋予权限:
mkdir /usr/local/pgsql/data
cd /usr/local/pgsql
chown postgres.postgres data
8、初始化数据库目录:
切换用户
su - postgresql
初始化数据
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
启动数据库
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
9、配置监听地址和端口:
vi /usr/local/pgsql/data/postgresql.conf
修改
listen_addresses = '*'
port = 5432
10、允许远程连接:
vi /usr/local/pgsql/data/pg_hba.conf
修改
host all all 0.0.0.0/0 trust
配置iptables让远程主机能访问:
vi /etc/sysconfig/iptables
添加
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5432 -j ACCEPT
service iptables restart
11、让postgresql数据库随系统启动而启动:
将启动脚本拷贝到/etc/init.d/目录下,具体执行如下命令:
cd /etc/rc.d/init.d
cp (第一步解压的安装文件目录)/postgresql-8.3.7/contrib/start-scripts/linux postgresql
chmod +x postgresql
vi postgresql
prefix=/usr/local/pgsql
PGDATA="/usr/local/pgsql/data"
PGUSER=postgres
PGLOG="/var/log/pgsql.log"
chkconfig --add postgresql
启动数据库:
service postgresql start
手动启动关闭:
su - postgres
pg_ctl start -D /usr/local/pgsql/data -o -i
pg_ctl stop -D /usr/local/pgsql/data -o -i
pg_ctl restart -D /usr/local/pgsql/data -o -i
psql 使用
[test@test bin]$ ./psql -n dbname -U usrname
stay81=# select count(*) from table1;
-------
(1 row)
// 退出,使用结束后退出,不然连接一直被挂起
stay81=# /q
数据备份还原
// postgres 数据导出
[postgres@test bin]$ ./pg_dump -U postgres -t testTable -d testDB > testTable.dump
// postgres 数据导入
[postgres@test bin]$ ./psql -U postgres -d testDB < testTable.dump
// postgres 数据导出
[postgres@test bin]$ ./pg_dump -U postgres -d stay81 -t item_search -F c -v > item_search.dump
// postgres 数据导入
[postgres@test bin]$ ./pg_restore -U postgres -d testDB < testTable.dump
// 一台主机上将数据库目录转储到另一台主机上
pg_dump -h host1 -p post1 dbname | psql -h host2 -p post1 dbname
./pg_dump -U postgres -d testDB1 -t testTable | ./psql -U postgres -d testDB2
- 在虚拟机(centos)配置postgresql数据库(1) - 安装篇
- 在虚拟机(centos)配置postgresql数据库(2) - 配置篇
- postgresql在centos上安装与配置
- win7下面在虚拟机centos里面安装配置memcache(1)-安装篇
- 【centos】配置postgresql数据库。
- CentOS安装PostgreSQL数据库
- 在虚拟机上安装centos并配置
- Linux(CentOS)下安装配置和使用PostgreSQL数据库
- Linux(CentOS)下Postgresql数据库的安装配置
- centos安装和配置postgresql,数据库版本可自定
- win7下面在虚拟机centos里面安装配置memcache(2)-脚本篇
- win7下面在虚拟机centos里面安装配置memcache(3)- 应用篇
- linux的数据库篇- PostgreSQL安装配置
- 在虚拟机(vmware)上安装CentOS
- CentOS 6.3下PostgreSQL 的安装与配置(rpm)
- mysql5.7.19在centos虚拟机下手动(离线)安装配置过程与一些问题解决办法
- centos下postgresql的安装与配置
- centos下postgresql的安装与配置
- Android 在post的表单中带上Cookie
- sticks
- EJB2.0之HelloWorld版本
- whatsApp 被收购随想: 做工具累积用户,跟巨头合作实现平台收益
- K近邻分类算法实现 in Python
- 在虚拟机(centos)配置postgresql数据库(1) - 安装篇
- 简化文件的绝对路径 Simpify Path
- C++ traits和enable_if的实现
- HDU4539
- 用ant实现SVN代码更新,部署
- apache虚拟主机
- OGNL表达式和EL表达式
- ortp库API说明
- MyEclipse去掉debug模式