本人测试系统为Ubuntu 12.04,本文不介绍Ubuntu的安装方法,在通用linux版本中使用自定义的二进制安装方法。
下载安装版本:wget http://get.enterprisedb.com/postgresql/postgresql-9.4.9-1-linux-x64-binarIEs.tar.gz
一、创建psotgres用户
groupadd postgres
useradd -g postgres postgres
二、创建必须目录
进入下载目录
tar xzfpostgresql-9.4.9-1-linux-x64-binarIEs.tar.gz -C /data/service
创建data目录:
mkdir -p /data/service/postgresql/data
mkdir -p /data/service/postgresql/log
授权:
chown -R postgres.postgres pgsql
chown -R postgres.postgres postgresql
这里如果不授权,后面初始化时候会报权限错误:
fixing permissions on existing directory /data/service/postgresql/data ... initdb: Could not change permissions of directory "/data/service/postgresql/data": Operation not permitted
三、初始化
进入解压后的目录,切换用户到postgresroot@s0142-gz:/data/service# su postgres $ bin/initdb -E utf8 -D /data/service/postgresql/data The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default text search configuration will be set to "english". Data page checksums are Disabled. fixing permissions on existing directory /data/service/postgresql/data ... ok creating subdirectorIEs ... ok selecting default max_connections ... 100 selecting default shared_buffers ... 128MB selecting dynamic shared memory implementation ... posix creating configuration files ... ok creating template1 database in /data/wulinzhi/service/postgresql/data/base/1 ... ok initializing pg_authID ... ok initializing dependencIEs ... ok creating system vIEws ... ok loading system objects' descriptions ... ok creating collations ... ok creating conversions ... ok creating dictionarIEs ... ok setting privileges on built-in objects ... ok creating information schema ... ok loading PL/pgsql server-sIDe language ... ok vacuuming database template1 ... ok copying template1 to template0 ... ok copying template1 to postgres ... ok syncing data to disk ... ok WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the option -A,or --auth-local and --auth-host,the next time you run initdb. Success. You can Now start the database server using: bin/postgres -D /data/service/postgresql/data or bin/pg_ctl -D /data/service/postgresql/data -l logfile start |
OK 看到这个表示已经初始化成功了。
我们先使用默认配置启动postgresql,如需修改配置参数,可以在data的目录下的postgresql.conf修改。
四、启动postgresql
启动注意必须使用postgres用户启动
postgres@s0142-gz:/data/service/pgsql/bin$ ./postgres -D /data/service/postgresql/data/ > /data/service/postgresql/log/postgres.log & [1] 36452 postgres@s0142-gz:/data/service/pgsql/bin$ LOG: database system was shut down at 2016-08-24 15:19:08 CST LOG: Multixact member wraparound protections are Now enabled LOG: database system is ready to accept connections LOG: autovacuum launcher started |
登录数据库:
postgres@s0142-gz:/data/wulinzhi/service/pgsql/bin$ ./psql psql.bin (9.4.9) Type "help" for help. No entry for terminal type "xterm"; using dumb terminal settings. postgres=# help You are using psql,the command-line interface to Postgresql. Type: \copyright for distribution terms \h for help with sql commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit postgres=# postgres=# \h Available help: ABORT ALTER TYPE CREATE SCHEMA DROP Language PREPARE ALTER AGGREGATE ALTER USER CREATE SEQUENCE DROP MATERIAliZED VIEW PREPARE TRANSACTION ALTER ColLATION ALTER USER MAPPing CREATE SERVER DROP OPERATOR REASSIGN OWNED ALTER CONVERSION ALTER VIEW CREATE table DROP OPERATOR CLASS REFRESH MATERIAliZED VIEW ALTER DATABASE ANALYZE CREATE table AS DROP OPERATOR FAMILY REINDEX ALTER DEFAulT PRIVILEGES BEGIN CREATE tableSPACE DROP OWNED RELEASE SAVEPOINT ALTER DOMAIN CHECKPOINT CREATE TEXT SEARCH CONfigURATION DROP RolE reset ALTER EVENT TRIGGER CLOSE CREATE TEXT SEARCH DICTIONARY DROP RulE REVOKE ALTER EXTENSION CLUSTER CREATE TEXT SEARCH PARSER DROP SCHEMA RolLBACK ALTER FOREIGN DATA WRAPPER COMMENT CREATE TEXT SEARCH TEMPLATE DROP SEQUENCE RolLBACK PREPARED ALTER FOREIGN table COMMIT CREATE TRIGGER DROP SERVER RolLBACK TO SAVEPOINT ALTER FUNCTION COMMIT PREPARED CREATE TYPE DROP table SAVEPOINT ALTER GROUP copY CREATE USER DROP tableSPACE Security LABEL ALTER INDEX CREATE AGGREGATE CREATE USER MAPPing DROP TEXT SEARCH CONfigURATION SELECT ALTER LANGUAGE CREATE CAST CREATE VIEW DROP TEXT SEARCH DICTIONARY SELECT INTO ALTER LARGE OBJECT CREATE ColLATION DEALLOCATE DROP TEXT SEARCH PARSER SET ALTER MATERIAliZED VIEW CREATE CONVERSION DECLARE DROP TEXT SEARCH TEMPLATE SET CONSTRAINTS ALTER OPERATOR CREATE DATABASE DELETE DROP TRIGGER SET RolE ALTER OPERATOR CLASS CREATE DOMAIN disCARD DROP TYPE SET SESSION AUTHORIZATION ALTER OPERATOR FAMILY CREATE EVENT TRIGGER DO DROP USER SET TRANSACTION ALTER RolE CREATE EXTENSION DROP AGGREGATE DROP USER MAPPing SHOW ALTER RulE CREATE FOREIGN DATA WRAPPER DROP CAST DROP VIEW START TRANSACTION ALTER SCHEMA CREATE FOREIGN table DROP ColLATION END table ALTER SEQUENCE CREATE FUNCTION DROP CONVERSION EXECUTE TruncATE ALTER SERVER CREATE GROUP DROP DATABASE EXPLAIN UNListEN ALTER SYstem CREATE INDEX DROP DOMAIN FETCH UPDATE ALTER table CREATE LANGUAGE DROP EVENT TRIGGER GRANT VACUUM ALTER tableSPACE CREATE MATERIAliZED VIEW DROP EXTENSION INSERT VALUES ALTER TEXT SEARCH CONfigURATION CREATE OPERATOR DROP FOREIGN DATA WRAPPER ListEN WITH ALTER TEXT SEARCH DICTIONARY CREATE OPERATOR CLASS DROP FOREIGN table LOAD ALTER TEXT SEARCH PARSER CREATE OPERATOR FAMILY DROP FUNCTION LOCK ALTER TEXT SEARCH TEMPLATE CREATE RolE DROP GROUP MOVE ALTER TRIGGER CREATE RulE DROP INDEX NOTIFY postgres=# |
到此postgresql安装完成,可以开始正常服务,大家如果想创建自己的数据库,用户和密码可以使用:
验证使用:
添加新用户和创建数据库
postgres=# create user wlz with password '123'; CREATE RolE postgres=# create database mydb with enCoding='utf8' owner=wlz; CREATE DATABASE |
验证登录
postgres@s0142-gz:/data/wulinzhi/service/pgsql/bin$ ./psql -U wlz -d mydb psql.bin (9.4.9) Type "help" for help. No entry for terminal type "xterm"; using dumb terminal settings. mydb=>
总结以上是内存溢出为你收集整理的PostgreSQL 二进制安装步骤全部内容,希望文章能够帮你解决PostgreSQL 二进制安装步骤所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)