zoukankan      html  css  js  c++  java
  • 在CentOS7(虚拟机)下通过源码安装Postgresql10以及基本配置

    操作系统:CentOS7
    安装文件:postgresql-10.0.tar.gz

    系统环境:gcc、Python

    1:源码安装

    [postgres@localhost ~]# tar zxvf postgresql-10.0.tar.gz
    [postgres@localhost ~]# mv postgresql-10.0 /usr/local/pgsql/
    [postgres@localhost ~]# cd /usr/local/pgsql/
    [root@localhost pgsql]# ./configure --prefix=/usr/local/pgsql --without-readline --without-zlib
    [root@localhost pgsql]# make
    [root@localhost pgsql]# make install

    2:添加postgres用户,设置目录权限

    [root@localhost ~]# adduser postgres
    [root@localhost ~]# passwd postgres
    [root@localhost ~]# mkdir -p /usr/local/pgsql/data
    [root@localhost ~]# chown -R posgres:root /usr/local/pgsql/
    [root@localhost ~]# chown -R postgres:root /usr/local/pgsql/

    3:设置环境变量

    [root@localhost ~]# su - postgres
    [postgres@localhost ~]$ vim ~/.bash_profile
    PATH=$PATH:/usr/local/pgsql/bin
    [postgres@localhost ~]$ source ~/.bash_profile 

    4:添加启动服务

    1)添加启动服务
    [root@localhost ~]# cp /usr/local/pgsql/contrib/start-scripts/linux /etc/init.d/postgresql
    [root@localhost ~]# chmod u+x /etc/init.d/postgresql 
    (2)添加开机自启动
    [root@localhost ~]# chkconfig --add postgresql
    (3)启动服务
    [root@localhost ~]# service postgresql start
    Starting PostgreSQL: ok

    5:切换到postgres用户,初始化数据库

    [postgres@localhost data]$ /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/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 "zh_CN.UTF-8".
    The default database encoding has accordingly been set to "UTF8".
    initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
    The default text search configuration will be set to "simple".
    
    Data page checksums are disabled.
    
    fixing permissions on existing directory /usr/local/pgsql/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
    running bootstrap script ... ok
    performing post-bootstrap initialization ... 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:
    
        /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

    6:修改postgresql配置

    1)允许所有连接
    [postgres@localhost ~]$ vi /usr/local/pgsql/data/pg_hba.conf
    # IPv4 local connections:
    host    all             all             0.0.0.0/0            trust
    (2)侦听所有连接
    [postgres@localhost ~]$ vi /usr/local/pgsql/data/postgresql.conf
    listen_addresses = '*'
    logging_collector = on

    7:启动数据库

    [postgres@localhost data]$  /usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
    waiting for server to start.... done
    server started

    8:设置postgres用户的密码

    [postgres@localhost ~]$ psql 
    psql (10.0)
    Type "help" for help.
    
    postgres=# password
    Enter new password: 
    Enter it again:

    9:查看当前数据库列表

    10:创建角色、数据库,切换数据库、用户

    postgres=# create role test login password 'test';   
    CREATE ROLE
    postgres=# create database testdb with owner=test;
    CREATE DATABASE
    postgres=# c testdb;
    You are now connected to database "testdb" as user "postgres".
    testdb=# c - test;
    You are now connected to database "testdb" as user "test".
    testdb=>

    11:本地通过pgAdmin4进行连接

  • 相关阅读:
    EnterpriseLibrary
    如何只保证窗口只打开一次[即只运行一个进程]
    设计模式之工厂方法模式
    设计模式之代理类
    asp.net mvc应用架构的思考--Unity的应用及三层代码
    为什么我说不要用TransactionScope
    Redis入门学习
    实战分层架构
    asp.net mvc 4多级area实现技巧
    jsonp其实很简单【ajax跨域请求】
  • 原文地址:https://www.cnblogs.com/yshyee/p/8962958.html
Copyright © 2011-2022 走看看