PostgreSQL 二进制安装步骤

前端之家收集整理的这篇文章主要介绍了PostgreSQL 二进制安装步骤前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

本人测试系统为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

三、初始化

进入解压后的目录,切换用户到postgres
root@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=>

原文链接:https://www.f2er.com/postgresql/194408.html

猜你在找的Postgre SQL相关文章