一,图形化的安装:
1,进入官网的下载页面:
http://www.postgresql.org/download/linux/
2,先修改文件权限:chmod 777 postgresql-9.2.4-1-linux-x64.run
3,安装:./postgresql-9.2.4-1-linux-x64.run
4,指定安装目录
5,指定数据文件的安装目录
6,指定 postgres 密码
7,指定端口号
8,指定 locale(使用默认的
Default local
【windows下选C】)
9,安装。
二,图形化的卸载:
1,直接
双击
安装目录下的
:uninstall-postgresql
2,卸载以后必定要重启机器,再从新安装该数据库
三,JDBC Driver for Java:
1,
http://jdbc.postgresql.org
安装前提:
yum install readline-devel
yum -y install zlib-devel
http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.gz
tar zxvf postgresql-9.2.4.tar.gz
cd postgresql-9.2.4
./configure
make
make install
pdAdmin
yum install
wxGTK-devel
yum -y install libxml2-devel
yum -y install libxslt-devel
yum -y install openssl-devel
http://ftp.postgresql.org/pub/pgadmin3/release/v1.8.4/src/pgadmin3-1.8.4.tar.gz
tar zxvf pgadmin3-1.8.4.tar.gz
cd pgadmin3-1.8.4
./configure
make
make install
四,命令行下的安装:
1,下载:
http://www.postgresql.org/ftp/source/
2,解压:tar zxvf postgresql-9.1.3.tar.gz
3,进入:cd postgresql-9.1.3
4,检查是否安装readline和readline-devel,没有则安装:yum -y install readline-devel
5,检查是否安装zlib-devel,没有则安装:yum -y install zlib-devel
6,配置:./configure --prefix=/usr/local/pgsql
7,编译:make(如出现:no acceptable C compiler found in $PATH,则需安装:yum -y install gcc)
8,安装:make install
9,建立用户组:groupadd postgres
10,建立用户:useradd -g postgres postgres
11,建立数据库文件的存储目录:mkdir /usr/local/pgsql/data
12,赋予数据库用户postgres的读写权限:先进入:cd /usr/local/pgsql,赋权限:chown postgres.postgres data
13,改变文件或目录时间:touch /var/log/pgsql.log
14,赋予数据库用户postgres的读写日志的权限:chown postgres.postgres /var/log/pgsql.log
15,切换用户:su - postgres
16,初始化数据:/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
17,启动数据库:/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l /var/log/pgsql.log start
18,配置监听地址和端口(其实就是取消'监听地址和端口'的注释,默认是注释了的):gedit /usr/local/pgsql/data/postgresql.conf,找到:listen_addresses = 'localhost'和port = 5432
19,设置PostgreSQL做为系统服务启动:先进入系统启动的目录:cd /etc/rc.d/init.d;复制解压的源文件进来:cp /root/postgresql-9.1.3/contrib/start-scripts/linux postgresql;改变文件的访问权限:chmod +x postgresql(+x:添加可执行权限);编辑:gedit postgresql
prefix=/usr/local/pgsql
PGDATA="/usr/local/pgsql/data"
PGUSER=postgres
PGLOG="
/var/log/pgsql.log
"(修改日志输出文件)
chkconfig --add postgresql
(添加这行)
启动数据库:service postgresql start
20,建立表:./createdb mydb(前提是在/usr/local/pgsql/bin目录下)
21,建立表的归属用户:./createuser -A -D -E -P mydb
22,输入第一次密码
23,再次输入密码
24,y(容许这个用户建立更多的角色)
25,进入数据库:./psql -d mydb -U mydb
26,出现:psql (9.1.3) /n Type "help" for help. 表示进入数据库
27,在前端提示符:mydb=>后输入:select version();就能够看到:PostgreSQL 9.1.3 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3), 32-bit(1 row)表示最新版的数据库已经安装成功,恭喜!
28,退出数据库:\q
29,使用postgres进入数据库:./psql -d postgres -U postgres
30,修改postgres密码:ALTER USER postgres WITH PASSWORD 'admin';
31,修改密码后需重启数据库服务,不然当前session没法生效。新开一个终端,输入:
/etc/rc.d/init.d/postgresql restart
,会出现:Restarting PostgreSQL: ok
基本操做:
\q:退出数据库
\l:显示全部的数据库
\c:链接到数据库
\d table:查看表结构
经常使用SQL语句:
1,查询数据库中存在的数据库:
select datname from pg_database;
自增字段初始值的设定:
select setval('testtable_id_seq', 1000, false);
Double 转 Integer:select 2.3 ::integer