postgresql数据库

postgrespl数据库(电脑编辑器有点问题稍后修改)

为什么使用postgresql

  • 在现有的数据库环境中postgresql数据库可以说是唯一一个纯免费的数据库。
  • 等等,

在linux上安装

  • pgsql官网地址: https://www.postgresql.org/ ,进入后点击download就来到下载页,这里点击Linux下面的Other Linux选项,然后点击下方的tar.gz archive下载二进制归档。

  • 然后就来到最终的pgsql下载页了,地址为: https://www.enterprisedb.com/download-postgresql-binaries ,自行选择对应的。

  • 安装并初始化:tar -xvzf postgresql-10.1-1-linux-x64-binaries.tar.gz
    解压出来 目录为pgsql
    mv pgsql/ /monchickey/
    [root@k8s-master1 /]# /usr/pgsql-10/bin/postgresql-10-setup initdb
    Initializing database ... OK #初始化成功

  • 或者直接使用命令安装

  • 安装rpm文件
    yum -y tall https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
    yum install postgresql10
    yum install postgresql10-serversystemctl enable postgresql-10

  • 初始化:/usr/pgsql-10/bin/postgresql-10-setup initdb

  • 设置开机自启:systemctl enable postgresql-10,systemctl start postgresql-10

自此我们就安装成功了

{{uploading-image-484697.png(uploading...)}}
运行并查看是否正常运行。

  • 配置一下:pgsql10配置文件位置默认在:/var/lib/pgsql/10/data/postgresql.conf

CONNECTIONS AND AUTHENTICATION

  • Connection Settings -

listen_addresses = 'localhost' # what IP address(es) to listen on; 本机ip以及本地localhost才能访问
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart) 端口号看自己情况

  • 日志参数,内存参数,自己找文档解析。

  • 认证权限配置文件: /var/lib/pgsql/9.6/data/pg_hba.conf

    命令行的各个参数解释说明:
    -U username 用户名,默认值postgres
    -d dbname 要连接的数据库名,默认值postgres。如果单指定-U,没指定-d参数,则默认访问与用户名名称相同的数据库。
    -h hostname 主机名,默认值localhost
    -p port 端口号,默认值5432

然后就是创建用户和数据库了

  • 使用postgresql用户登录
  • create user test_user with password 'abc123'; // 创建用户
    create database test_db owner test_user; // 创建数据库
    grant all privileges on database test_db to test_user; // 授权
  • 退出psql(输入 \q 再按回车键即可)

最后就是使用了:https://www.cnblogs.com/orangeform/archive/2012/06/08/2315679.html

或者打开远程使用Navicat工具使用

posted @ 2022-06-06 09:56  whml  阅读(543)  评论(0)    收藏  举报