Pgsql


安装前提:

GUN make 版本:

sudo make –version

GNU Make 3.81

#建议3.76.1或者更高版本

需要一个ISO/ANSIC编译器(至少兼容C89)。GCC

缺省时将自动使用GNU Readline 库(这样可以方便地编辑和检索命令历史)。它允许psql(PostgreSQL命令行的SQL解释)记住每个命令类型,并允许您使用箭头键召回和编辑以前的命令。这是非常有用的,并且强烈推荐。如果你不想用它,那么你必需给configure声明--without-readline选项。如果没有发现 libreadline 可以使用与其兼容的libedit 库。为configure指定--with-libedit-preferred选项将强制使用libedit 库。 如果你使用的是一个基于包的 Linux 发布,那么要注意你需要readline和readline-devel 两个包,特别是如果这两个包在你的版本里是分开的时候

缺省的时候将使用zlib压缩库。如果你不想使用它,那么你必须给configure声明--without-zlib选项。使用这个选项关闭了在pg_dump 和pg_restore里面压缩归档的支持

下载:
sudo apt-get install zlib1g-dev
sudo wget http://ftp.postgresql.org/pub/source/v9.3.4/postgresql-9.3.4.tar.gz
sudo tar xvf postgresql-9.3.4.tar
cd postgresql-9.3.4/
sudo ./configure  --prefix=/usr/local/postgresql--without-readlinesudo
make world
sudo make install-world
初始化数据库
sudo mkdir -p /usr/local/postgresql/data
sudo groupadd  postgres
useradd -g postgres  postgres
sudo passwd postgres
sudo chown -R  postgres:postgres  /usr/local/postgresql/data/
 
sudo su postgres
cd /usr/local/postgresql/bin/
./initdb --encoding=utf8 -D ../data/

启动数据库:
./postgres -D ../data/ &
或者
./pg_ctl -D ../data/ -l logfile start

如果想在同一台机器中部署两个数据库实例,则可以再使用initdb命令将数据库初始化到另一个目录中,此目录要更改为postgres用户拥有权限,初始化完成后更改端口即可。

配置PostgreSQL远程访问连接:(注意这里使用postgres账户操作)

cd /usr/local/postgresql/data/
sed -i "/#listen_addresses = ‘localhost‘/s/localhost/listen_addresses= ‘0‘/" postgresql.conf
sed -i "/#port =5432/s/#port/port/" postgresql.conf
sed -i "85a\host    all             all             0.0.0.0/0            md5" pg_hba.conf
重启数据库
./pg_ctl -D ../data/  restart

启动脚本如下:
#! /bin/sh
 
# chkconfig: 2345 98 02
# description: PostgreSQL RDBMS
 
# This is an example of a start/stop scriptfor SysV-style init, such
# as is used on Linux systems.  You should edit some of the variables
# and maybe the ‘echo‘ commands.
#
# Place this file at /etc/init.d/postgresql(or
# /etc/rc.d/init.d/postgresql) and makesymlinks to
#  /etc/rc.d/rc0.d/K02postgresql
#  /etc/rc.d/rc1.d/K02postgresql
#  /etc/rc.d/rc2.d/K02postgresql
#  /etc/rc.d/rc3.d/S98postgresql
#  /etc/rc.d/rc4.d/S98postgresql
#  /etc/rc.d/rc5.d/S98postgresql
# Or, if you have chkconfig, simply:
# chkconfig --add postgresql
#
# Proper init scripts on Linux systemsnormally require setting lock
# and pid files under /var/run as well asreacting to network
# settings, so you should treat this withcare.
 
# Original author:  Ryan Kirkpatrick <[email protected]>
 
# contrib/start-scripts/linux
 
## EDIT FROM HERE
 
# Installation prefix
prefix=/usr/local/pgsql
 
# Data directory
PGDATA="/usr/local/pgsql/data"
 
# Who to run the postmaster as, usually"postgres".  (NOT"root")
PGUSER=postgres
 
# Where to keep a log file
PGLOG="$PGDATA/serverlog"
 
# It‘s often a good idea to protect thepostmaster from being killed by the
# OOM killer (which will tend topreferentially kill the postmaster because
# of the way it accounts for sharedmemory).  Setting the OOM_SCORE_ADJ value
# to -1000 will disable OOM killaltogether.  If you enable this, youprobably
# want to compile PostgreSQL with"-DLINUX_OOM_SCORE_ADJ=0", so that
# individual backends can still be killedby the OOM killer.
#OOM_SCORE_ADJ=-1000
# Older Linux kernels may not have/proc/self/oom_score_adj, but instead
# /proc/self/oom_adj, which works similarlyexcept the disable value is -17.
# For such a system, enable this andcompile with "-DLINUX_OOM_ADJ=0".
#OOM_ADJ=-17
 
## STOP EDITING HERE
 
# The path that is to be used for thescript
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
# What to use to start up thepostmaster.  (If you want the script towait
# until the server has started, you coulduse "pg_ctl start -w" here.
# But without -w, pg_ctl adds no value.)
DAEMON="$prefix/bin/postmaster"
 
# What to use to shut down the postmaster
PGCTL="$prefix/bin/pg_ctl"
 
set -e
 
# Only start if we can find the postmaster.
test -x $DAEMON ||
{
       echo "$DAEMON not found"
       if [ "$1" = "stop" ]
       then exit 0
       else exit 5
       fi
}
 
 
# Parse command line parameters.
case $1 in
 start)
       echo -n "Starting PostgreSQL: "
       test x"$OOM_SCORE_ADJ" != x && echo"$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
       test x"$OOM_ADJ" != x && echo "$OOM_ADJ"> /proc/self/oom_adj
       su - $PGUSER -c "$DAEMON -D ‘$PGDATA‘ &" >>$PGLOG2>&1
       echo "ok"
       ;;
 stop)
       echo -n "Stopping PostgreSQL: "
       su - $PGUSER -c "$PGCTL stop -D ‘$PGDATA‘ -s -m fast"
       echo "ok"
       ;;
 restart)
       echo -n "Restarting PostgreSQL: "
       su - $PGUSER -c "$PGCTL stop -D ‘$PGDATA‘ -s -m fast -w"
       test x"$OOM_SCORE_ADJ" != x && echo"$OOM_SCORE_ADJ" > /proc/self/oom_score_adj
       test x"$OOM_ADJ" != x && echo "$OOM_ADJ"> /proc/self/oom_adj
       su - $PGUSER -c "$DAEMON -D ‘$PGDATA‘ &" >>$PGLOG2>&1
       echo "ok"
       ;;
 reload)
       echo -n "Reload PostgreSQL: "
       su - $PGUSER -c "$PGCTL reload -D ‘$PGDATA‘ -s"
       echo "ok"
       ;;
 status)
       su - $PGUSER -c "$PGCTL status -D ‘$PGDATA‘"
       ;;
  *)
       # Print help
       echo "Usage: $0 {start|stop|restart|reload|status}"1>&2
       exit 1
       ;;
esac
 
exit 0

将此脚本修改然后放置到/etc/init.d/postgres01

sudo chmod +x /etc/init.d/postgres01
sudo update-rc.d  -n postgresql01 defaults 98
查找安装工具包(管理系统服务)
sudo apt-cache search  ^sysv
sudo apt-get  install sysv-rc-conf
sudo sysv-rc-conf

时间: 2024-08-07 00:18:04

Pgsql的相关文章

关于pgsql 的json 和jsonb 的数据查询操作笔记整理

关于pgsql 的json 和jsonb 的数据处理笔记 1. json 和jsonb 区别两者从用户操作的角度来说没有区别,区别主要是存储和读取的系统处理(预处理)和耗时方面有区别.json写入快,读取慢,jsonb写入慢,读取快. 2. 常用的操作符 操作符: -> // 右边传入整数(针对纯数组),获取数组的第n个元素,n从0开始算,返回值为json 示例: select '[{"a":"foo"},{"b":"bar&qu

准备在新项目中使用pgsql

pgsql大象数据库 是我最近在关注的一款开源数据库,可以自由修改,没那么多限制,准备在新项目中使用 http://blog.163.com/[email protected]/blog/static/16387704020141229159715/

PgSQL简单操作

********************************************** *基本操作 ********************************************** 数据库操作 $ psql test $ psql -h localhost -U username -W newpwd -p 5432 test =# create database mail_db; =# create database mail_db owner sunny; =# drop d

PgSql备份pg_dump与还原手记pg_restore

真没有想到,以前一直是PostgreSQL使用者,突然需要库移植又成了头一招了!原来它与mysql命令行操作区别还挺大.不用怕,但绝对要细心,因为数据库操作是网站的核心,一旦出现损坏或丢失,后果就非常严重了.我先写了步骤,然后按计划进行,虽然也出现了错误,但最终还是安全移植了.这里记录在案,以备后用.备份还原方法:pg_dump和pg_restore,先仔细说明这两个命令,再记录我的操作方法. pg_dump --  将一个PostgreSQL数据库抽出到一个脚本文件或者其它归档文件中pg_du

辛星浅析PL/pgsql语法(上)

最近在研究postgresql,因此也就对PL/pgsql产生了浓厚的兴趣,因此这里就来稍微的总结一下,首先说一下的是这个PL是Procedure Language的简写,也就是所谓的"过程语言". 下面的很大一部分内容都是引用自pgsql手册,但是也根据自己的理解进行了一些简单的改变. 第一,调用时机 其中PL/pgsql的函数被第一次调用的时候,其函数内的源代码会被解析为二进制指令树,但是对于函数内的表达式还有一些指令,只有在被首次使用的时候,pgsql才会给它制定执行计划,而且这

刀塔传奇公会管理系统 ------ Pgsql 后台

背景: 系统会给出公会人员的情况,例如 几月几日XXXX加入公会,几月几日XXXX离开工会. 系统会给出所有人最近七天的活跃总数. 需要计算出所有人最近七天的平均活跃情况,加入时间不足七天的玩家,按实际天数计算. 数据存储方式选择: 1.   开始使用的Excel做的,编写了一些宏,增加了一个按钮来触发这个宏.数据稍微一多,弊病就露出来了. 输入活跃数据时,需要手动寻找名字在第几行.多天的数据整理需要手工处理,数据量大时很容易造成数据错乱或数据丢失. 2.  计划使用Access数据库来存储,但

PDO连接mysql和pgsql数据库

PDO连接mysql数据库 1 <?php 2 $dsn="mysql:host=localhsot;dbname=lamp87"; 3 $user="root"; 4 $passwd="123"; 5 $m = new PDO($dsn,$user,$passwd); 6 $stmt = $m->query("select * from stu"); 7 $rows = $stmt->fetchAll();

刀塔传奇公会管理系统 ------ Python界面访问Pgsql

今天时间不多了,只能写一部分了. Python连接Pgsql的库有三个,目前 psycopg2 用的比较多,随即下载安装了.没什么难点,参考个例子就能用了. 图形界面使用 wx 的库,因为这个有个相当好用的图形制作的工具 ----   wxFormBuilder. 有了这个,你可以单刀直入的去设计你的图形界面的样子.真真正正的实现了界面与功能的分离,设计这个玩意的人思想很牛逼. 使用方法就是,画好界面(同时写上每个事件的回调函数名字),将生成的python代码(其实可以生成好多种语言的)保存到一

WINDOW下php开启pgsql拓展

操作步骤: 1.修改php.ini,去掉“extension=php_pgsql.dll ”和“extension=php_pdo_pgsql.dll ”前的分号.2.确认C:\php\ext\下php_pgsql.dll存在3.修改path环境变量,添加了postgresql的bin目录4.进入postgresql的bin目录,复制如下文件到c:\WINDOWS\system32下, 5.重启apache,运行phpinfo.php,出现如下结果则加载成功. WINDOW下php开启pgsql

pgsql 到底用的那个conf文件?

gvim /var/lib/pgsql/data/postgresql.conf gvim /var/lib/pgsql/data/pg_hba.conf service httpd start service postgresql start [[email protected] ~]# psql -h 127.0.0.1 -U dbuser -d david -p 5432psql (8.4.18)Type "help" for help. david=> \quit [[e