PostgreSQL

来自开放百科 - 灰狐
(版本间的差异)
跳转到: 导航, 搜索
(Add short brief introduction)
(项目)
 
(未显示6个用户的304个中间版本)
第1行: 第1行:
[[Image:Postgresql.jpeg|right]]
+
[[Image:Postgresql.jpg]]  PostgreSQL: 世界上最高级的开源数据库
[[Image:Postgresql.jpg]]  PostgreSQL: The world's most advanced open source database
+
 
 +
==新闻==
 +
{{SeeWikipedia}}
 +
访问 https://planet.postgresql.org/ 了解PostgreSQL最新动态。
 +
 
 
==简介==
 
==简介==
 +
[[Image:Postgresql-90x90.png|right]]
 
PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统。
 
PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统。
  
第14行: 第19行:
 
总而言之,PostgreSQL的特性已经完全可以满足绝大部分用户的需要,而且其质量和特性仍然在日新月异地进步着,所以, 我们有理由相信在不远的将来,PostgreSQL 肯定能够成为一种优秀的,自由的,商业数据库的替代产品。
 
总而言之,PostgreSQL的特性已经完全可以满足绝大部分用户的需要,而且其质量和特性仍然在日新月异地进步着,所以, 我们有理由相信在不远的将来,PostgreSQL 肯定能够成为一种优秀的,自由的,商业数据库的替代产品。
  
最新版:8.2 http://blogs.huihoo.com/?p=307
+
==版本==
 +
===13===
 +
*[https://www.postgresql.org/docs/13/release.html PostgreSQL 13]
 +
*[https://www.postgresql.org/about/press/presskit13/zh/ PostgreSQL 13 Released!](24th September 2020)
 +
 
 +
===12===
 +
*[https://www.postgresql.org/docs/12/release.html PostgreSQL 12]
 +
 
 +
===11===
 +
*[https://www.postgresql.org/docs/11/release.html PostgreSQL 11]
 +
*[https://mp.weixin.qq.com/s?__biz=MzIzNjUxMzk2NQ==&mid=2247489373&idx=1&sn=1c61a6302157c01c7362ed2ea7bb73a2&chksm=e8d7e89fdfa0618913c283ac860df3e6b182edaeb979b16ed3680eaf9ebab246d3dc3f2c8b49&scene=27#wechat_redirect PostgreSQL 11 第一个测试版发布,增加哪些新功能?]
 +
 
 +
===10===
 +
*[https://www.postgresql.org/docs/10/static/release-10-4.html PostgreSQL 10.4]
 +
 
 +
===9.6===
 +
*[https://www.postgresql.org/docs/9.6/static/release-9-6-9.html PosgreSQL 9.6.9]
 +
 
 +
===9.5===
 +
*[https://www.postgresql.org/docs/9.5/static/release-9-5-13.html PostgreSQL 9.5.13]
 +
 
 +
===9.4===
 +
[[PostgreSQL/9.4|PostgreSQL 9.4]]
 +
 
 +
===9.3===
 +
[http://www.postgresql.org/about/news/1481/ PostgreSQL 9.3 正式发布]
 +
 
 +
===9.2===
 +
[[PostgreSQL/9.2|PostgreSQL 9.2]]
 +
 
 +
===9.x===
 +
[[PostgreSQL/9.0|PostgreSQL 9.0]] 正式版[http://www.postgresql.org/about/news.1235 发布]
 +
 
 +
[http://www.postgresql.org/about/featurematrix Feature Matrix]
  
 
==安装指南==
 
==安装指南==
  ./configure
+
  ./configure --with-perl // Pl/PerlU
 
  gmake // ln -s /usr/bin/make /usr/bin/gmake
 
  gmake // ln -s /usr/bin/make /usr/bin/gmake
 
  su
 
  su
第26行: 第64行:
 
  su - postgres // sudo su postgres  
 
  su - postgres // sudo su postgres  
 
  /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data  
 
  /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data  
  /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >logfile 2>&1 &
+
  /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data & or
 +
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
 
  /usr/local/pgsql/bin/createdb test
 
  /usr/local/pgsql/bin/createdb test
 
  /usr/local/pgsql/bin/psql test
 
  /usr/local/pgsql/bin/psql test
 +
netstat -plunt | grep 5432
  
 +
gmake 可能出现的问题 /usr/bin/ld: cannot find -lperl
 +
 +
apt-get install libperl-dev
 +
 +
可能遇见的问题:could not bind IPv4 socket: Cannot assign requested address
 +
 +
修改 /usr/local/pgsql/data/postgresql.conf
 +
 +
listen_addresses = 'localhost,192.168.1.101'
 +
 +
error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory
 +
  ldd /home/pgsql/bin/psql
 +
linux-gate.so.1 =>  (0xf76ec000)
 +
libpq.so.5 => not found
 +
 +
vi /etc/ld.so.conf,加入
 +
/home/pgsql/lib
 +
 然后执行:ldconfig  OK:)
 +
===端口开放===
 +
iptables -L
 +
vim /etc/iptables.rules
 +
-A INPUT -p tcp --dport 5432 -j ACCEPT
 +
iptables-restore < /etc/iptables.rules
 +
 +
postgresql.conf
 +
listen_addresses = '*'
 +
port = 5432
 +
 +
pg_hba.conf
 +
host all all 0.0.0.0/0 md5
 +
 +
===Debian===
 +
PGDG(PostgreSQL全球开发组) 维护着[http://wiki.postgresql.org/wiki/Apt PostgresSQL的Debian仓库]
 +
 +
创建 /etc/apt/sources.list.d/pgdg.list
 +
deb http://apt.postgresql.org/pub/repos/apt/ sid-pgdg main // sid 换成 wheezy、squeeze
 +
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
 +
sudo apt-get update
 +
sudo apt-get install postgresql pgadmin3
 +
$ sudo su - postgres
 +
$ createuser huihoo
 +
$ createdb testdb -O huihoo
 +
$ psql testdb
 +
testdb=# alter user huihoo with password 'huihoo.com';
 +
 +
===OS X===
 +
维护着最新版本PostgeSQL的安装
 +
https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb
 +
brew info postgresql
 +
brew install postgresql
 +
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
 +
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
 +
postgres -D /usr/local/var/postgres -i -l &
 +
 +
[http://www.postgresql.org/download/macosx Mac OS X packages]
 +
*或者 [http://postgresapp.com/ Postgres.app] 便捷安装。
 +
*或者 安装 [[EnterpriseDB]] 很方便。
 +
 +
===Windows===
 +
在Windows下使用非安装版, 如 [http://get.enterprisedb.com/postgresql/postgresql-9.0.0-1-windows-binaries.zip postgresql-9.0.0-1-windows-binaries.zip]
 +
 +
先解压到PostgreSQL包到 D:\pgsql
 +
 +
在命令行输入 runas /usr:postgres cmd // 切换到 postgres 账号
 +
创建 data 的文件夹 D:\pgsql\mkdir data
 +
D:\pgsql\bin\initdb.exe -D D:\pgsql\data -E UTF8 --locale=C
 +
D:\pgsql\bin\pg_ctl.exe register -D d:\pgsql\data -N pg9.0 // 注册Windows服务
 +
net start pg9.0 (启动数据库)
 +
net stop pg9.0 (关闭数据库)
 +
 +
===8.3===
 +
debian 5.0.3 readline not found
 +
apt-get install bison,flex,libreadline5-dev 问题解决
 +
apt-get install zlib1g-dev 解决 zlib没安装的问题
 
stop postgresql  
 
stop postgresql  
 
  su postgres or sudo su postgres  
 
  su postgres or sudo su postgres  
 
  /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data/
 
  /usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data/
  
注意: postgres在默认是不接受tcp/ip连接的。有两种方式来控制它接受tcp/ip连接,一种是用启动参数 -i ,另一种方式是修改数据库目录里的文件:postgresql.conf中的参数,将tcpip_socket = false改为true port = 5432 前面的注释符号去掉。表示接受tcp/ip在5432的连接。
+
注意: postgres在默认是不接受tcp/ip连接的。有两种方式来控制它接受tcp/ip连接,一种是用启动参数 -i ,另一种方式是修改数据库目录里的文件:postgresql.conf中的参数,将tcpip_socket = false改为true port = 5432 前面的注释符号去掉。表示接受tcp/ip在5432的连接。(The tcpip_socket variable from postgres 7.4 is not recognized with postgres 8.1)version 8.0, this is controlled using the "listen_addresses"parameter in the postgresql.conf.
 +
listen_addresses = 'localhost'
 +
listen_addresses = '*' // * = all
 +
listen_addresses = '192.168.1.2','192.168.1.3'
 +
 
 +
vi pg_hba.conf
 +
local all all md5
 +
host all all 127.0.0.1/32 md5
 +
 
 +
# IPv4 local connections:
 +
host all all 192.168.1.100 255.255.255.0 password
 +
host all all 127.0.0.1 255.255.255.255 trust
 +
host all postgres 127.0.0.1 255.255.255.255 password
 +
host all all 0.0.0.0/0 md5
 +
host all all 192.168.1.0/16 trust
 +
or
 +
host all all 127.0.0.1/32 md5
 +
host all all 192.168.0.0/24 md5
 +
host all all 172.18.0.0/16 md5
 +
or
 +
host all all 172.18.0.0/16 trust
 +
修改后重启:
 +
/etc/init.d/postgresql-7.4 restart
 +
创建一测试用户: test
 +
# edit file /etc/postgresql/pg_hba.conf, and lines at file top:
 +
local  test      test                                          md5
 +
host    test      test    127.0.0.1        255.255.255.255    md5
 +
# su - postgres
 +
$ createuser -ADPE test
 +
$ createdb -O test test
 +
$ createlang plpgsql test
 +
$ exit
 +
# psql -h 127.0.0.1 -U test test
 +
 
 +
==Examples==
 +
http://pgfoundry.org/projects/dbsamples/ - A collection of sample databases for PostgreSQL.
 +
 
 +
请下载 dellstore2 ,大家可用这些数据做实验 :)
 +
 
 +
如 Dell Store2 database http://linux.dell.com/dvdstore/ , dbsamples 对 dvdstore database 做了 PosgreSQl port,在[http://download.huihoo.com/dell/dvdstore 灰狐的镜像]。
 +
 
 +
[http://docs.huihoo.com/postgresql/dellstore2.html Dell Store2 Physical Data Diagram]
 +
 
 +
createdb -E LATIN1 dellstore2 -U postgres
 +
createlang plpgsql dellstore2 -U postgres
 +
psql -f dellstore.sql dellstore2 -U postgres or psql -f dellstore.sql dellstore2 postgres // windows
 +
 
 +
对其它数据库,如 mysql 请下载 ds2.tar.gz 和 ds2_mysql.tar.gz, 并解压到同一目录下, 并事先创建 DS2 数据库和 web/web 的用户信息
  
 
==命令==
 
==命令==
 +
[[Image:PostgresqlArchitecture.gif|thumb|right|PostgreSQL 体系结构和进程概况]]
 
* createdb—Creates a new database in postgreSQL. A database name is required when using this command.
 
* createdb—Creates a new database in postgreSQL. A database name is required when using this command.
 
* createuser—Creates a postgreSQL user. A user name is required when using this command.
 
* createuser—Creates a postgreSQL user. A user name is required when using this command.
第48行: 第210行:
 
  $ createdb mydb
 
  $ createdb mydb
 
  $ dropdb mydb
 
  $ dropdb mydb
  $ psql mydb
+
$ cd src/tutorial
 +
$ export PATH=$PATH:/usr/local/pgsql/bin
 +
  $ psql
 +
postgres=# \l 列出所有数据库或 bash-3.1$ psql -l
 +
$ psql -s mydb
 +
alter user postgres with password 'postgres'; // 密码修改生效,可能要修改 pg_hba.conf 的认证方式: md5, trust
 +
alter database test owner to postgres;
 +
mydb=> \dt 命令是显示表
 +
mydb=> \di 显示索引
 +
mydb=> \ds 显示序列
 +
mydb=> \dv 显示视图
 +
mydb=> \dp 显示权限
 +
mydb=> \dS 显示系统表
 +
mydb=> \dl 显示 lobjects
 +
mydb=> \d tablename 显示表的结构/索引/序列
 +
mydb=> \d indexname 显示索引的详细信息
 +
mydb=> \i basics.sql or basics.source 导入表
 
  mydb=> SELECT version();
 
  mydb=> SELECT version();
 +
mydb=> show all; // 显示运行时参数的数值
 +
备份和恢复
 
  pg_dump -x databasename > outfile
 
  pg_dump -x databasename > outfile
 +
pg_dump.exe -h localhost -p 5432 -U huihoo -F c -b -v -f "D:\backup\opentaps1.0.4.backup" "opentaps1.0.4"
 
  psql -e database < outfile
 
  psql -e database < outfile
   
+
  pg_restore.exe -h localhost -p 5432 -U huihoo -d "opentaps1.0.4" -v "D:\backup\opentaps1.0.4.backup"
 +
 
 
  CREATE TABLE weather (
 
  CREATE TABLE weather (
 
     city            varchar(80),
 
     city            varchar(80),
第61行: 第243行:
 
  );
 
  );
 
  DROP TABLE tablename;
 
  DROP TABLE tablename;
   
+
 
 +
连接(join)查询
 +
  SELECT *
 +
      FROM weather w, cities c
 +
      WHERE w.city = c.name;
 +
 
 
  postgres@debian:~$ psql -l
 
  postgres@debian:~$ psql -l
 
         List of databases
 
         List of databases
第74行: 第261行:
 
  template1=# select * from pg_tables;
 
  template1=# select * from pg_tables;
 
  template1=# create user huihoo password 'huihoo' createdb;
 
  template1=# create user huihoo password 'huihoo' createdb;
 +
 +
mydb=# select md5('abc');
 +
mydb=# select btrim('xyxtrimyyx','xy');
 +
mydb=# select ltrim('zzzytrim','xyz');
 +
http://docs.huihoo.com/postgresql/postgresql-doc-7.4-zh_CN/functions-string.html
  
 
==PostgreSQL Limits==
 
==PostgreSQL Limits==
第86行: 第278行:
  
 
==PostgreSQL发行版==
 
==PostgreSQL发行版==
*EnterpriseDB http://www.enterprisedb.com/
+
*Amalgamated Insight  ...  proprietary  ...  Fork of TelegraphCQ
*Pervasive http://www.pervasive.com/
+
*Bizgres ... BSD ... PostgreSQL + BI features
 +
*Bizgres MPP ... proprietary ... PostgreSQL + BI features
 +
*EnterpriseDB ... proprietary ... PostgreSQL + Oracle compatibility
 +
*ExtenDB ... proprietary ... PostgreSQL + BI Features
 +
*Great Bridge PostgreSQL ... BSD ... PostgreSQL re-distribution
 +
*Mammoth ... BSD ... PostgreSQL + contrib modules
 +
*Netezza ... proprietary ... Appliance based on PostgreSQL SQL engine
 +
*NuSphere UltraSQL ... proprietary ... Native Win32 port of PostgreSQL
 +
*parACCEL ... proprietary ... PostgreSQL + BI features
 +
*Pervasive PostgreSQL ... BSD ... PostgreSQL re-distribution
 +
*PowerGres ... proprietary ... Native Win32 port of PostgreSQL
 +
*PowerGres Plus ... proprietary ... PostgreSQL + custom storage engine
 +
*PostgreSQL for Solaris 10 ... BSD ... PostgreSQL re-distribution
 +
*Red Hat Database ... BSD ... PostgreSQL re-distribution
 +
*TelegraphCQ ... BSD ... Data Stream oriented fork of PostgresSQL
 +
from http://www.postgresql.org/docs/techdocs.62
 +
--------
 +
*[[EnterpriseDB]] http://www.enterprisedb.com/
 +
*[[Pervasive]] http://www.pervasive.com/
 +
*[[PostgreSQL Red Hat Edition]] http://sourceware.org/rhdb/
 +
 
 +
==图形客户端==
 +
* [https://github.com/pgmodeler/pgmodeler pgModeler]
 +
* [[SQuirreL SQL Client]]
 +
* [[pgAdmin]] III - Cross-platform administration tool
 +
* [[PhpPgAdmin]] - Web-based PostgreSQL administration tool
 +
* [[pgDesigner]] - Datamodel designer for PostgreSQL
 +
 
 +
==PostGIS==
 +
[[PostGIS]]在对象关系型数据库PostgreSQL上增加了存储管理空间数据的能力,相当于Oracle的spatial部分。PostGIS最大的特点是符合并且实现了OpenGIS的一些规范,是最著名的开源GIS数据库。
 +
==HA,Scaleable==
 +
*[[Postgres-XL]]
 +
*[https://github.com/tencent/tbase TBase]
 +
*[[pgpool]]
 +
*[[Greenplum]]
 +
*http://www.linuxlabs.com
 +
*[[Slony-I]]
 +
*[[Usogres]]
 +
*[[PGCluster]]
 +
*[http://www.commandprompt.com/products/mammothreplicator/ Mammoth PostgreSQL Replication]
 +
*[[pgmemcache]]
 +
[http://wiki.postgresql.org/wiki/Replication%2C_Clustering%2C_and_Connection_Pooling Replication, Clustering, and Connection Pooling]
 +
*[http://docs.huihoo.com/oreilly/conferences/strataconf/big-data-conference-2014/Scalable-PostgreSQL-as-your-data-platform.pdf Scalable PostgreSQL as your data platform]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2013/PostgreSQL-9-High-Availability-with-Linux-HA.pdf PostgreSQL 9 High Availability with Linux-HA]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2013/Implementing-High-Availability.pdf Implementing High Availability]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2012/Postgres-XC-tutorial-Configuring-write-scalable-PostgreSQL-cluster.pdf Postgres­XC Tutorial - Configuring write-scalable PostgreSQL cluster]
 +
*[https://github.com/zalando/patroni Patroni] A Template for PostgreSQL HA with [[Apache ZooKeeper]], [[etcd]] or [[Consul]]
 +
Patroni是一个基于 Python 的 PostgreSQL 控制器,它利用分布式配置存储(例如etcd, ZooKeeper, Consul)管理PostgreSQL 集群的状态。同时它还支持流复制和同步复制模型,并提供了一组丰富的REST API,用于PostgreSQL集群的动态配置。如果你想在分布式PostgreSQL设置中实现高可用性,并且不得不考虑许多边缘情况,令人欣慰的是,Patroni 提供了模板来实现常见的用例。(来源:[https://docs.huihoo.com/thoughtworks/technology-radar/technology-radar-vol-18-cn.pdf Technology Radar])
 +
 
 +
==Cloud==
 +
[[文件:cloud-database.png]]
 +
*[https://docs.microsoft.com/zh-cn/azure/postgresql/ Azure Database for PostgreSQL]
 +
*[http://aws.amazon.com/cn/rds/postgresql/ Amazon RDS for PostgreSQL]
 +
*[http://docs.huihoo.com/amazon/aws/whitepapers/RDBMS-in-the-Cloud-PostgreSQL-on-AWS-June-2013.pdf RDBMS in the Cloud: PostgreSQL on AWS]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2012/PostgreSQL-on-AWS.pdf PostgreSQL on AWS]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2014/Postgres-in-Amazon-RDS.pdf Postgres in Amazon RDS]
 +
*[http://aws.amazon.com/cn/redshift/ Amazon Redshift – 云数据仓库解决方案]
 +
*[https://www.heroku.com/postgres Heroku Postgres], [https://devcenter.heroku.com/categories/heroku-postgres The SQL database service for developers].
 +
*[https://aiven.io/postgresql Aiven PostgreSQL]
 +
*[https://github.com/crunchydata Crunchy Data] Crunchy PostgreSQL for [[Kubernetes]]
 +
 
 +
==BigData/Storage==
 +
*[[CitusDB]]
 +
*[http://db.cs.yale.edu/hadoopdb/hadoopdb.html HadoopDB] - hybrid of MapReduce and DBMS.
 +
*[http://www-01.ibm.com/software/data/netezza/ IBM Netezza] - high-performance data warehouse appliances.
 +
*[http://www.postgres-xl.org/ Postgres-XL] - Scalable Open Source PostgreSQL-based Database Cluster.
 +
*[http://www-users.cs.umn.edu/~sarwat/RecDB/ RecDB] - Open Source Recommendation Engine Built Entirely Inside PostgreSQL.
 +
*[http://www.stormdb.com/community/stado Stado] - open source MPP database system solely targeted at data warehousing and data mart applications.
 +
*[http://www.scribd.com/doc/3159239/70-Everest-PGCon-RT Yahoo Everest] - multi-peta-byte database / MPP derived by PostgreSQL.
 +
*[http://docs.huihoo.com/postgresql/pgcon/2013/The-Billion-Tables-Project.pdf The Billion Tables Project]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2014/Gaia-Mapping-a-billion-stars-throughout-our-Galaxy-and-beyond.pdf Gaia: Mapping a billion stars throughout our Galaxy and beyond]
 +
 
 +
*[http://www.sun.com/solutions/landing/infrastructure/dwa/ Sun Data Warehouse Appliance]
 +
Powered by best-in-class open source software including the Solaris Operating System (OS), PostgreSQL, and ZFS.
 +
 
 +
http://www.greenplum.com/solutions/sun_Appliance.php
 +
*[[MonoSphere]]
 +
 
 +
==DW,BI==
 +
*[[Greenplum]]: Massively-Parallel, Shared-Nothing Database based on PostgreSQL.
 +
*[http://docs.huihoo.com/postgresql/data-warehousing-with-postgresql-2009.pdf Data warehousing with PostgreSQL]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2009/Building-PetaByte-Warehouses-with-Unmodified-PostgreSQL.pdf Building PetaByte Warehouses with Unmodified PostgreSQL]
 +
*[http://www.postgresql.org/about/news/909/ Analytic SQL Server - next generation analytic Data Warehouse with OLAP support]
 +
 
 +
==内存数据库==
 +
*[http://docs.huihoo.com/postgresql/pgcon/2014/In-Memory-Columnar-Store-extension-for-PostgreSQL.pdf In-Memory Columnar Store extension for PostgreSQL]
 +
*[[In-memory database]] for PostgreSQL
 +
*[http://vschart.com/compare/voltdb/vs/postgresql VoltDB vs. PostgreSQL]
 +
 
 +
==时序数据库==
 +
[[Time series database]]
 +
*[[TimescaleDB]]
 +
 
 +
==NoSQL==
 +
PostgreSQL [[NoSQL]] Style
 +
 
 +
*[http://docs.huihoo.com/postgresql/pgcon/2013/One-step-forward-true-json-data-type.pdf One step forward true json data type]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2010/Perspectives-on-NoSQL.pdf Perspectives on NoSQL]
 +
 
 +
[[文件:mongodb-v2.6-postgresql-v9.4-50mil-records-numeric.png]]
 +
 
 +
*[http://www.infoq.com/cn/news/2014/09/postgres-outperforms-mongodb PostgreSQL的NoSQL特性表现抢眼,多个方面优于MongoDB]
 +
 
 +
==GPU==
 +
[https://wiki.postgresql.org/wiki/PGStrom PGStrom] PostgreSQL的[[GPU]]加速
 +
 
 +
[[image:PostgreSQL-PGStrom.png|PGStorm]]
 +
 
 +
==C,C++==
 +
*[[SOCI]]
 +
*[[QtSqlView]]
 +
*[[libpqxx]]
 +
*[http://docs.huihoo.com/postgresql/8.4/client-interfaces.html PostgreSQL Client Interfaces]
 +
 
 +
==Go==
 +
*[https://github.com/sosedoff/pgweb pgweb]
 +
 
 +
==Ruby==
 +
gem install activerecord-postgresql-adapter
 +
gem install pg
 +
export RAILS_ENV=production
 +
vim Gemfile , add
 +
gem 'pg'
 +
rake db:create
 +
rake db:migrate
 +
 
 +
==PHP==
 +
[[Image:postgresql-php.gif|right]]
 +
 
 +
==Python==
 +
==Java==
 +
driver: org.postgresql.Driver
 +
url: jdbc:postgresql://host:port/database
 +
database.url = jdbc:postgresql://localhost:5432/test?charSet=utf8
 +
// database.url = jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true
 +
*http://jdbc.postgresql.org/
 +
*http://download.huihoo.com/postgresql/
 +
 
 +
==.NET==
 +
[[Npgsql]]
 +
 
 +
==JavaScript==
 +
*[[node.js]] (integrate with 9.2's [[JSON]] and [[PL/v8]])
 +
*[http://github.com/commandprompt/postgres-js PostgreSQL for JavaScript]: 一个实现了PostgreSQL前/后端协议的[[JavaScript]]库。
 +
 
 +
==迁移==
 +
将用户从 [[Oracle]], [[DB2]], [[Microsoft SQL Server]], [[MySQL]] 等数据库迁移到 PostgreSQL
 +
*[http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL Converting from other Databases to PostgreSQL]
 +
===Oracle===
 +
*[http://yq.aliyun.com/articles/2718 Oracle和PostgreSQL的最新版本性能PK, PostgreSQL 9.5.0和Oracle 12c]
 +
*[[pgORA]]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2011/Migrating-Oracle-databases-to-PostgreSQL-Best-practices.pdf Migrating Oracle databases to PostgreSQL Best practices]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2008/Porting-Oracle-Applications-to-PostgreSQL.pdf Porting Oracle Applications to PostgreSQL]
 +
*[[Openbravo]] [http://wiki.openbravo.com/wiki/ERP_2.50:Oracle_to_PostgreSQL_migration Oracle to PostgreSQL migration]
 +
*[http://docs.huihoo.com/postgresql/pgcon/2014/A-Tale-of-Two-Oracle-Migrations-Deploying-PostgreSQL-at-Japan-second-largest-stock-exchange.pdf "A Tale of Two Oracle Migrations" Deploying PostgreSQL at Japan's second-largest stock exchange]
 +
 
 +
===DB2===
 +
===SQL Server===
 +
*[[tPostgres]]
 +
*[http://docs.huihoo.com/postgresql/migration-application-from-mssql-to-postgresql-zh-cn.pdf MSSQL到PostgreSQL的应用迁移]
 +
*[http://wiki.postgresql.org/wiki/Microsoft_SQL_Server_to_PostgreSQL_Migration_by_Ian_Harding Microsoft SQL Server to PostgreSQL Migration by Ian Harding]
 +
 
 +
===MySQL===
 +
*[http://docs.huihoo.com/postgresql/pgcon/2012/Large-Scale-MySQL-Migration-to-PostgreSQL.pdf Large Scale MySQL Migration to PostgreSQL]
 +
*[http://wiki.postgresql.org/wiki/How_to_make_a_proper_migration_from_MySQL_to_PostgreSQL How to make a proper migration from MySQL to PostgreSQL]
 +
 
 +
==项目==
 +
*[https://github.com/dhamaniasad/awesome-postgres Awesome Postgres] [[文件:awesome.png]]
 +
*[https://www.postgresql.org/download/product-categories/ PostgreSQL-related interfaces, extensions and software]
 +
*[[CitusDB]]
 +
*[[Greenplum]]
 +
*[[Postgres-XL]]
 +
*[[pgmemcache]]
 +
*[[PgBouncer]]
 +
*[[SkyTools]]
 +
*[[PL/Proxy]]
 +
*[[pg_bulkload]]
 +
*[[PgWorksheet]]
 +
*[[pgpool]]
 +
*[[PostgresPy]]
 +
*[[PostgreSQL Build Farm]]
 +
*[[mysql2pgsql]]
 +
*[[Autodoc]]
 +
*[https://github.com/zombodb/zombod ZomboDB] Making PostgreSQL and [[Elasticsearch]] work together
 +
More Projects:
 +
*http://pgfoundry.org/
 +
*http://gborg.postgresql.org/
 +
*[https://github.com/pgvector/pgvector pgvector] 用于Postgres的开源向量相似性搜索
 +
 
 +
==商业支持==
 +
*Fujitsu Supported PostgreSQL - http://postgresql.fastware.com
 +
*PostgreSQL for Solaris 10 - http://www.sun.com/software/solaris/postgresql.jsp
 +
 
 +
==成功应用==
 +
*http://reddit.com - http://programming.reddit.com/info/tgj7/comments/ctgt8
 +
*http://hi5.com
 +
hi5 includes multiple terabytes of data and media files stored across an array of PostgreSQL databases and an EXT3 file system. The hi5 application was written in Java and runs on hundreds of [[Resin]] application servers and Apache web servers. The data center is filled with machines ranging from Dell Blades, SuperMicros, Dell 8-way Servers – most of which run SuSE Linux.
 +
*yahoo
 +
雅虎数据库技术最初出自于2005年底被雅虎低调收购的Mahat技术公司。雅虎使用的数据库是深度改良的PostgreSQL,用为其商用硬件集群专门设计的代码来取代查询处理层。传统的数据排列方式是按照行进行的,而雅虎则选择用分布式列来存储数据。
 +
*[http://pgcon-2012-keynote.herokuapp.com/ Heroku ♥ Postgres]
 +
 
 +
==文档==
 +
*[http://docs.huihoo.com/gputechconf/gtc2015/S5276-PG-Strom-Query-Acceleration-Engine-of-PostgreSQL-Powered-by-GPGPU.pdf PG-Strom: Query Acceleration Engine of PostgreSQL Powered by GPGPU]
 +
*[http://docs.huihoo.com/postgresql/data-warehousing-with-postgresql-2009.pdf Data warehousing with PostgreSQL]
  
 
==在线文档==
 
==在线文档==
*PostgreSQL 8.1 中文文档 - http://www.huihoo.com/postgresql/pgsqldoc-8.1c/
+
*[http://developer.postgresql.org/pgdocs/postgres/ PostgreSQL devel Documentation]
*PostgreSQL 8.0.0 中文文档 - http://www.huihoo.com/postgresql/postgresql-doc-8.0-zh_CN/
+
*[http://docs.huihoo.com/postgresql/9.1/ PostgreSQL 9.1 English Document]
*PostgreSQL 7.4 中文文档 - http://www.huihoo.com/postgresql/postgresql-doc-7.4-zh_CN/
+
*[http://docs.huihoo.com/postgresql/9.0/ PostgreSQL 9.0 English Document]
*PostgreSQL 7.3.3 中文文档 - http://www.huihoo.com/postgresql/pgsql-doc-7.3/
+
*[http://docs.huihoo.com/postgresql/9.3-zh-CN/ PostgreSQL 9.3 中文手册]
*PostgreSQL 7.1.1 中文文档 - http://www.huihoo.com/postgresql/pgsqldoc-7.1C/postgres.html
+
*[http://docs.huihoo.com/postgresql/pgsqldoc-8.1c/ PostgreSQL 8.1 中文文档]
 +
*[http://docs.huihoo.com/postgresql/postgresql-doc-8.0-zh_CN/ PostgreSQL 8.0.0 中文文档]
 +
*[http://docs.huihoo.com/postgresql/postgresql-doc-7.4-zh_CN/ PostgreSQL 7.4 中文文档]
 +
*[http://docs.huihoo.com/postgresql/pgsql-doc-7.3/ PostgreSQL 7.3.3 中文文档]
 +
*[http://docs.huihoo.com/postgresql/pgsqldoc-7.1C/postgres.html PostgreSQL 7.1.1 中文文档]
 +
[http://docs.huihoo.com/postgresql/ 更多文档>>>]
 +
*[https://github.com/postgres-cn/pgdoc-cn PostgreSQL中文手册翻译计划]
 +
*[https://wiki.postgresql.org/wiki/Category:Chinese 中文维基]
  
==相关链接==
+
==Mailing Lists==
 +
*[http://archives.postgresql.org/ PostgreSQL mailing list archives]
 +
 
 +
==Debian==
 +
PostgreSQL on [[Debian]]
 +
 +
创建 /etc/apt/sources.list.d/pgdg.list
 +
lsb_release -c
 +
添加 deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main
 +
 
 +
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
 +
or wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
 +
sudo apt-get update
 +
sudo apt-get install postgresql pgadmin3
 +
*[https://wiki.postgresql.org/wiki/Apt PostgreSQL packages for Debian and Ubuntu]
 +
 
 +
==[[OpenSolaris]]==
 +
[http://www.sun.com/software/products/postgresql/features.jsp PostgreSQL for Solaris]
 +
Blogs on PostgreSQL
 +
* Josh Berkus:    http://blogs.ittoolbox.com/database/soup
 +
* Jignesh Shah: http://blogs.sun.com/jkshah/
 +
* Paul van den Bogaard:  http://blogs.sun.com/paulvandenbogaard/
 +
* Robert Lor:  http://blogs.sun.com/robertlor/
 +
* Tom Daly: http://blogs.sun.com/tomdaly/
 +
 
 +
PostgreSQL on Solaris Wiki: http://wikis.sun.com/display/DBonSolaris/PostgreSQL
 +
 
 +
==MySQL to PostgreSQL==
 +
[http://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL Converting from other Databases to PostgreSQL]
 +
 
 +
==PostgreSQL and MySQL==
 +
*[https://www.2ndquadrant.com/en/postgresql/postgresql-vs-mysql/ PostgreSQL vs MySQL]
 +
[[Image:mammoth_versus_dolphin_500.jpg|right|thumb|PostgreSQL will eat MySQL for lunch :)]]
 +
*Ten times out of ten, PostgreSQL will eat MySQL for lunch (and twice on Sunday).I don't benefit from this at all, but, if you're a PostgreSQL user, DBA, programmer, hacker, etc., and like that logo
 +
from http://people.freebsd.org/~seanc/
 +
*[http://www.zhihu.com/question/20010554 PostgreSQL 与 MySQL 相比,优势何在?]
 +
 
 +
==PostgreSQL and Redis==
 +
*更好融合 [[Redis]]
 +
*[http://www.pgxn.org/dist/redis_fdw/ redis_fdw]
 +
 
 +
==Buttons==
 +
[[Image:postgresql_80x15.png]] [[File:postgresql-137x30.png]]
 +
 
 +
==图集==
 +
<gallery>
 +
image:PostgreSQL-9.6-parallel-query.png|PgSQL9.6并行查询
 +
image:postgresql-cloud-database-create-cluster.png|云数据库
 +
image:postgresql-data-provider-npgsql.png|.NET和Npgsql
 +
image:postgresql-data-warehouse.png|数据仓库
 +
image:bigsql-architecture.png|PostgreSQL与大数据
 +
image:yahoo-everest-architecture.png|Yahoo Everest
 +
image:postgresql-9.5-pk-oracle-12c.jpg|与Oracle性能PK
 +
image:Gartner-Magic-Quadrant-for-Operational-Database-Management-Systems-October-2015.png|Gartner魔力象限
 +
image:2UDA-Big-Data-Analytics-with-PostgreSQL.jpg|大数据分析
 +
image:apache-madlib-architecture.png|MADlib架构
 +
image:crunchy-certified-postgresql.png|Crunchy Certified PostgreSQL
 +
image:Crunchy-Containers-for-PostgreSQL.png|Crunchy容器
 +
image:crunchy-postgresql-for-kubernetes.png|Kubernetes
 +
</gallery>
 +
 
 +
==用户==
 +
*阿里巴巴
 +
*[https://www.gandi.ne Gandi.net] using PostgreSQL for the Gandi IAAS/PAAS platform and recently internally, to build one of our live systems that stores/computes/outputs millions rows daily, very easily.
 +
*http://reddit.com
 +
*http://www.openstreetmap.org/ [http://blog.cleverelephant.ca/2009/04/openstreetmap-moves-to-postgresql.html OpenStreetMap moves to PostgreSQL]
 +
*[http://gitbook.cn/books/58db93b8f59193805502b491/index.html 饿了么 PostgreSQL 优化之旅]
 +
 
 +
==书籍==
 +
*[http://book.huihoo.com/postgresql-introduction-and-concepts/ PostgreSQL: Introduction and Concepts]
 +
<gallery widths=100px heights=100px perrow=6>
 +
Image:postgresql-90-high-performance.jpg|
 +
</gallery>
 +
 
 +
==链接==
 
*http://www.postgresql.org
 
*http://www.postgresql.org
 
*pgAdmin http://www.pgadmin.org/
 
*pgAdmin http://www.pgadmin.org/
 
*phpPgAdmin http://phppgadmin.sourceforge.net
 
*phpPgAdmin http://phppgadmin.sourceforge.net
 
*PostgreSQL 中文网 http://www.pgsqldb.org/
 
*PostgreSQL 中文网 http://www.pgsqldb.org/
 +
*http://docs.huihoo.com/postgresql/
 +
*http://download.huihoo.com/postgresql/
 +
*数据库迁移:将你的网站从MySQL改为PostgreSQL http://linux.chinaunix.net/docs/2006-12-06/3413.shtml
 +
*PostgreSQL BuildFarm http://www.pgbuildfarm.org
 +
*[http://pgxn.org/ PGXN, the PostgreSQL Extension network]
 +
*[http://www.infoq.com/cn/articles/byebye-mongodb-hello-postgresql 再见MongoDB,你好PostgreSQL]
 +
*[https://blog.lateral.io/2015/05/full-text-search-in-milliseconds-with-postgresql/ Full text search in milliseconds with PostgreSQL]
 +
*[https://github.com/digoal/blog 德哥 / digoal's github - 公益是一辈子的事.]
 +
@网路冷眼【PostgreSQL毫秒级全文本搜索】本文并没有采用 Apache Solr后者Elasticsearch的开源方案,也没有采用Elastic或者Algolia的托管方案,而是采用了Postgres来做全文本搜索,并解释了这种方式的优点,不失为搜索的一种解决方案。
 +
*[https://www.migops.com/blog/2021/07/16/centos-vs-rocky-linux-benchmark-with-postgresql/ CentOS vs Rocky Linux Benchmark with PostgreSQL]
  
==精彩图集==
+
[[category:database]]
[[Image:PostgresqlArchitecture.gif|thumb|left|PostgreSQL 体系结构和进程概况]]
+
[[category:PostgreSQL]]
 
+
[[category:huihoo]]
[[category:Open source database management systems]]
+

2023年3月21日 (二) 09:26的最后版本

Postgresql.jpg PostgreSQL: 世界上最高级的开源数据库

目录

[编辑] 新闻

Wikipedia-35x35.png 您可以在Wikipedia上了解到此条目的英文信息 PostgreSQL Thanks, Wikipedia.

访问 https://planet.postgresql.org/ 了解PostgreSQL最新动态。

[编辑] 简介

Postgresql-90x90.png

PostgreSQL 是一种非常复杂的对象-关系型数据库管理系统(ORDBMS),也是目前功能最强大,特性最丰富和最复杂的自由软件数据库系统。

PostgreSQL 的特性覆盖了 SQL-2/SQL-92 和 SQL-3/SQL-99,首先,它包括了可以说是目前世界上最丰富的数据类型的支持,其中有些数据类型可以说连商业数据库都不具备, 比如 IP 类型和几何类型等;其次,PostgreSQL 是全功能的自由软件数据库,很长时间以来,PostgreSQL 是唯一支持事务、子查询、多版本并行控制系统、数据完整性检查等特性的唯一的一种自由软件的数据库管理系统。直到最近才有 Inprise 的 InterBase 以及 SAP 等厂商将其原先专有软件开放为自由软件之后才打破了这个唯一。

PostgreSQL 提供了统一的客户端 C 接口。而不同的客户端接口都是源自这个 C 接口,比如 ODBC,JDBC,Python,Perl ,Tcl,C/C++,ESQL 等。

PostgreSQL 已经完全可以胜任任何中上规模范围内的应用范围的业务。目前有报道的生产数据库的大小已经有 TB 级的数据量,已经逼近 32 位计算的极限。 PostgreSQL是目前支持平台最多的数据库管理系统的一种, 所支持的平台多达十几种,包括不同的系统,不同的硬件体系。至今,它仍然保持着支持平台最多的数据库管理系统的称号。

PostgreSQL 的确还欠缺一些比较高端的数据库管理系统需要的特性,比如联机热备份,数据库集群,更优良的管理工具和更加自动化的系统优化功能 等提高数据库性能的机制等。

总而言之,PostgreSQL的特性已经完全可以满足绝大部分用户的需要,而且其质量和特性仍然在日新月异地进步着,所以, 我们有理由相信在不远的将来,PostgreSQL 肯定能够成为一种优秀的,自由的,商业数据库的替代产品。

[编辑] 版本

[编辑] 13

[编辑] 12

[编辑] 11

[编辑] 10

[编辑] 9.6

[编辑] 9.5

[编辑] 9.4

PostgreSQL 9.4

[编辑] 9.3

PostgreSQL 9.3 正式发布

[编辑] 9.2

PostgreSQL 9.2

[编辑] 9.x

PostgreSQL 9.0 正式版发布

Feature Matrix

[编辑] 安装指南

./configure --with-perl // Pl/PerlU
gmake // ln -s /usr/bin/make /usr/bin/gmake
su
gmake install
adduser postgres
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres // sudo su postgres 
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data 
/usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data  & or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
netstat -plunt | grep 5432

gmake 可能出现的问题 /usr/bin/ld: cannot find -lperl

apt-get install libperl-dev

可能遇见的问题:could not bind IPv4 socket: Cannot assign requested address

修改 /usr/local/pgsql/data/postgresql.conf

listen_addresses = 'localhost,192.168.1.101'

error while loading shared libraries: libpq.so.5: cannot open shared object file: No such file or directory

 ldd /home/pgsql/bin/psql

linux-gate.so.1 => (0xf76ec000) libpq.so.5 => not found

vi /etc/ld.so.conf,加入
/home/pgsql/lib

 然后执行:ldconfig OK:)

[编辑] 端口开放

iptables -L

vim /etc/iptables.rules

-A INPUT -p tcp --dport 5432 -j ACCEPT

iptables-restore < /etc/iptables.rules

postgresql.conf

listen_addresses = '*'
port = 5432

pg_hba.conf

host all all 0.0.0.0/0 md5

[编辑] Debian

PGDG(PostgreSQL全球开发组) 维护着PostgresSQL的Debian仓库

创建 /etc/apt/sources.list.d/pgdg.list

deb http://apt.postgresql.org/pub/repos/apt/ sid-pgdg main // sid 换成 wheezy、squeeze
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get install postgresql pgadmin3
$ sudo su - postgres
$ createuser huihoo
$ createdb testdb -O huihoo
$ psql testdb
testdb=# alter user huihoo with password 'huihoo.com';

[编辑] OS X

维护着最新版本PostgeSQL的安装 https://github.com/Homebrew/homebrew/blob/master/Library/Formula/postgresql.rb

brew info postgresql
brew install postgresql
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
postgres -D /usr/local/var/postgres -i -l & 

Mac OS X packages

[编辑] Windows

在Windows下使用非安装版, 如 postgresql-9.0.0-1-windows-binaries.zip

先解压到PostgreSQL包到 D:\pgsql

在命令行输入 runas /usr:postgres cmd // 切换到 postgres 账号

创建 data 的文件夹 D:\pgsql\mkdir data
D:\pgsql\bin\initdb.exe -D D:\pgsql\data -E UTF8 --locale=C 
D:\pgsql\bin\pg_ctl.exe register -D d:\pgsql\data -N pg9.0 // 注册Windows服务
net start pg9.0 (启动数据库)
net stop pg9.0 (关闭数据库)

[编辑] 8.3

debian 5.0.3 readline not found

apt-get install bison,flex,libreadline5-dev 问题解决
apt-get install zlib1g-dev 解决 zlib没安装的问题

stop postgresql

su postgres or sudo su postgres 
/usr/local/pgsql/bin/pg_ctl stop -D /usr/local/pgsql/data/

注意: postgres在默认是不接受tcp/ip连接的。有两种方式来控制它接受tcp/ip连接,一种是用启动参数 -i ,另一种方式是修改数据库目录里的文件:postgresql.conf中的参数,将tcpip_socket = false改为true port = 5432 前面的注释符号去掉。表示接受tcp/ip在5432的连接。(The tcpip_socket variable from postgres 7.4 is not recognized with postgres 8.1)version 8.0, this is controlled using the "listen_addresses"parameter in the postgresql.conf.

listen_addresses = 'localhost'
listen_addresses = '*' // * = all
listen_addresses = '192.168.1.2','192.168.1.3'

vi pg_hba.conf

local	all	all	md5
host all all 127.0.0.1/32 md5
 
# IPv4 local connections:
host all all 192.168.1.100 255.255.255.0 password
host all all 127.0.0.1 255.255.255.255 trust
host all postgres 127.0.0.1 255.255.255.255 password
host all all 0.0.0.0/0 md5
host all all 192.168.1.0/16 trust 
or 
host all all 127.0.0.1/32 md5
host all all 192.168.0.0/24 md5
host all all 172.18.0.0/16 md5
or
host all all 172.18.0.0/16 trust

修改后重启:

/etc/init.d/postgresql-7.4 restart

创建一测试用户: test

# edit file /etc/postgresql/pg_hba.conf, and lines at file top:
local   test       test                                          md5
host    test       test     127.0.0.1         255.255.255.255    md5
# su - postgres
$ createuser -ADPE test
$ createdb -O test test
$ createlang plpgsql test
$ exit
# psql -h 127.0.0.1 -U test test

[编辑] Examples

http://pgfoundry.org/projects/dbsamples/ - A collection of sample databases for PostgreSQL.

请下载 dellstore2 ,大家可用这些数据做实验 :)

如 Dell Store2 database http://linux.dell.com/dvdstore/ , dbsamples 对 dvdstore database 做了 PosgreSQl port,在灰狐的镜像

Dell Store2 Physical Data Diagram

createdb -E LATIN1 dellstore2 -U postgres
createlang plpgsql dellstore2 -U postgres
psql -f dellstore.sql dellstore2 -U postgres or psql -f dellstore.sql dellstore2 postgres // windows

对其它数据库,如 mysql 请下载 ds2.tar.gz 和 ds2_mysql.tar.gz, 并解压到同一目录下, 并事先创建 DS2 数据库和 web/web 的用户信息

[编辑] 命令

PostgreSQL 体系结构和进程概况
  • createdb—Creates a new database in postgreSQL. A database name is required when using this command.
  • createuser—Creates a postgreSQL user. A user name is required when using this command.
  • dropdb—Removes a database from postgreSQL. A database name is required when using this command.
  • dropuser—Removes a postgreSQL user. A user name is required when using this command.
  • initdb—Creates a new postgreSQL database installation. This command is used only once when the database is installed. It creates the base directory. This command cannot be used again.
  • psql—SQL interface to the postgreSQL databases. A database name is required when using this command.
  • vacuumdb—Cleans and analyzes a postgreSQL database.

[编辑] 常用用法

$ createdb mydb
$ dropdb mydb
$ cd src/tutorial
$ export PATH=$PATH:/usr/local/pgsql/bin
$ psql
postgres=# \l 列出所有数据库或 bash-3.1$ psql -l
$ psql -s mydb 
alter user postgres with password 'postgres'; // 密码修改生效,可能要修改 pg_hba.conf 的认证方式: md5, trust
alter database test owner to postgres;
mydb=> \dt 命令是显示表
mydb=> \di 显示索引
mydb=> \ds 显示序列
mydb=> \dv 显示视图
mydb=> \dp 显示权限
mydb=> \dS 显示系统表
mydb=> \dl 显示 lobjects
mydb=> \d tablename 显示表的结构/索引/序列
mydb=> \d indexname 显示索引的详细信息
mydb=> \i basics.sql or basics.source 导入表
mydb=> SELECT version();
mydb=> show all; // 显示运行时参数的数值
备份和恢复
pg_dump -x databasename > outfile
pg_dump.exe -h localhost -p 5432 -U huihoo -F c -b -v -f "D:\backup\opentaps1.0.4.backup" "opentaps1.0.4"
psql -e database < outfile
pg_restore.exe -h localhost -p 5432 -U huihoo -d "opentaps1.0.4" -v "D:\backup\opentaps1.0.4.backup"
CREATE TABLE weather (
   city            varchar(80),
   temp_lo         int,           -- 最低气温
   temp_hi         int,           -- 最高气温
   prcp            real,          -- 降水量
   date            date
);
DROP TABLE tablename;

连接(join)查询

SELECT *
      FROM weather w, cities c
      WHERE w.city = c.name;
postgres@debian:~$ psql -l
       List of databases
   Name    |  Owner   | Encoding
-----------+----------+----------
 template0 | postgres | EUC_CN
 template1 | postgres | EUC_CN
 test      | postgres | EUC_CN
(3 rows)
postgres@debian:~$ psql template1
template1=# select * from pg_tables;
template1=# create user huihoo password 'huihoo' createdb;
mydb=# select md5('abc');
mydb=# select btrim('xyxtrimyyx','xy');
mydb=# select ltrim('zzzytrim','xyz');

http://docs.huihoo.com/postgresql/postgresql-doc-7.4-zh_CN/functions-string.html

[编辑] PostgreSQL Limits

Limit Value

  • Maximum Database Size Unlimited
  • Maximum Table Size 32 TB
  • Maximum Row Size 1.6 TB
  • Maximum Field Size 1 GB
  • Maximum Rows per Table Unlimited
  • Maximum Columns per Table 250 - 1600 depending on column types
  • Maximum Indexes per Table Unlimited

[编辑] PostgreSQL发行版

  • Amalgamated Insight ... proprietary ... Fork of TelegraphCQ
  • Bizgres ... BSD ... PostgreSQL + BI features
  • Bizgres MPP ... proprietary ... PostgreSQL + BI features
  • EnterpriseDB ... proprietary ... PostgreSQL + Oracle compatibility
  • ExtenDB ... proprietary ... PostgreSQL + BI Features
  • Great Bridge PostgreSQL ... BSD ... PostgreSQL re-distribution
  • Mammoth ... BSD ... PostgreSQL + contrib modules
  • Netezza ... proprietary ... Appliance based on PostgreSQL SQL engine
  • NuSphere UltraSQL ... proprietary ... Native Win32 port of PostgreSQL
  • parACCEL ... proprietary ... PostgreSQL + BI features
  • Pervasive PostgreSQL ... BSD ... PostgreSQL re-distribution
  • PowerGres ... proprietary ... Native Win32 port of PostgreSQL
  • PowerGres Plus ... proprietary ... PostgreSQL + custom storage engine
  • PostgreSQL for Solaris 10 ... BSD ... PostgreSQL re-distribution
  • Red Hat Database ... BSD ... PostgreSQL re-distribution
  • TelegraphCQ ... BSD ... Data Stream oriented fork of PostgresSQL

from http://www.postgresql.org/docs/techdocs.62


[编辑] 图形客户端

[编辑] PostGIS

PostGIS在对象关系型数据库PostgreSQL上增加了存储管理空间数据的能力,相当于Oracle的spatial部分。PostGIS最大的特点是符合并且实现了OpenGIS的一些规范,是最著名的开源GIS数据库。

[编辑] HA,Scaleable

Replication, Clustering, and Connection Pooling

Patroni是一个基于 Python 的 PostgreSQL 控制器,它利用分布式配置存储(例如etcd, ZooKeeper, Consul)管理PostgreSQL 集群的状态。同时它还支持流复制和同步复制模型,并提供了一组丰富的REST API,用于PostgreSQL集群的动态配置。如果你想在分布式PostgreSQL设置中实现高可用性,并且不得不考虑许多边缘情况,令人欣慰的是,Patroni 提供了模板来实现常见的用例。(来源:Technology Radar)

[编辑] Cloud

Cloud-database.png

[编辑] BigData/Storage

Powered by best-in-class open source software including the Solaris Operating System (OS), PostgreSQL, and ZFS.

http://www.greenplum.com/solutions/sun_Appliance.php

[编辑] DW,BI

[编辑] 内存数据库

[编辑] 时序数据库

Time series database

[编辑] NoSQL

PostgreSQL NoSQL Style

Mongodb-v2.6-postgresql-v9.4-50mil-records-numeric.png

[编辑] GPU

PGStrom PostgreSQL的GPU加速

PGStorm

[编辑] C,C++

[编辑] Go

[编辑] Ruby

gem install activerecord-postgresql-adapter
gem install pg
export RAILS_ENV=production
vim Gemfile , add 
gem 'pg'
rake db:create
rake db:migrate

[编辑] PHP

Postgresql-php.gif

[编辑] Python

[编辑] Java

driver: org.postgresql.Driver
url: jdbc:postgresql://host:port/database
database.url = jdbc:postgresql://localhost:5432/test?charSet=utf8
// database.url = jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf8&autoReconnect=true

[编辑] .NET

Npgsql

[编辑] JavaScript

[编辑] 迁移

将用户从 Oracle, DB2, Microsoft SQL Server, MySQL 等数据库迁移到 PostgreSQL

[编辑] Oracle

[编辑] DB2

[编辑] SQL Server

[编辑] MySQL

[编辑] 项目

More Projects:

[编辑] 商业支持

[编辑] 成功应用

hi5 includes multiple terabytes of data and media files stored across an array of PostgreSQL databases and an EXT3 file system. The hi5 application was written in Java and runs on hundreds of Resin application servers and Apache web servers. The data center is filled with machines ranging from Dell Blades, SuperMicros, Dell 8-way Servers – most of which run SuSE Linux.

  • yahoo

雅虎数据库技术最初出自于2005年底被雅虎低调收购的Mahat技术公司。雅虎使用的数据库是深度改良的PostgreSQL,用为其商用硬件集群专门设计的代码来取代查询处理层。传统的数据排列方式是按照行进行的,而雅虎则选择用分布式列来存储数据。

[编辑] 文档

[编辑] 在线文档

更多文档>>>

[编辑] Mailing Lists

[编辑] Debian

PostgreSQL on Debian

创建 /etc/apt/sources.list.d/pgdg.list

lsb_release -c
添加 deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main
wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
or wget --quiet -O - http://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | apt-key add -
sudo apt-get update
sudo apt-get install postgresql pgadmin3

[编辑] OpenSolaris

PostgreSQL for Solaris Blogs on PostgreSQL

PostgreSQL on Solaris Wiki: http://wikis.sun.com/display/DBonSolaris/PostgreSQL

[编辑] MySQL to PostgreSQL

Converting from other Databases to PostgreSQL

[编辑] PostgreSQL and MySQL

PostgreSQL will eat MySQL for lunch :)
  • Ten times out of ten, PostgreSQL will eat MySQL for lunch (and twice on Sunday).I don't benefit from this at all, but, if you're a PostgreSQL user, DBA, programmer, hacker, etc., and like that logo

from http://people.freebsd.org/~seanc/

[编辑] PostgreSQL and Redis

[编辑] Buttons

Postgresql 80x15.png Postgresql-137x30.png

[编辑] 图集

[编辑] 用户

[编辑] 书籍

[编辑] 链接

@网路冷眼【PostgreSQL毫秒级全文本搜索】本文并没有采用 Apache Solr后者Elasticsearch的开源方案,也没有采用Elastic或者Algolia的托管方案,而是采用了Postgres来做全文本搜索,并解释了这种方式的优点,不失为搜索的一种解决方案。

分享您的观点
个人工具
名字空间

变换
操作
导航
工具箱