• DeepinV20/Ubuntu安装postgresql方法


    首先,建议看一下官方的安装文档PostgreSQL: Linux downloads (Ubuntu)

    PostgreSQL Apt Repository

    简单的说,就是Ubuntu下的Apt仓库,可以用来安装任何支持版本的PgSQL。

    If the version included in your version of Ubuntu is not the one you want, you can use the PostgreSQL Apt Repository. This repository will integrate with your normal systems and patch management, and provide automatic updates for all supported versions of PostgreSQL throughout the support lifetime of PostgreSQL.

    sort by https://zhengkai.blog.csdn.net/

    The PostgreSQL Apt Repository supports the current versions of Ubuntu:

    • kinetic (22.10, non-LTS)
    • jammy (22.04, LTS)
    • focal (20.04, LTS)
    • bionic (18.04, LTS)
    • LinuxDeepin V20 (DeepinV23应该也适用)

    Installation steps

    # Create the file repository configuration:
    sudo sh -c 'echo "deb https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
    
    # Import the repository signing key:
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    
    

     

    # Update the package lists:

    # 配置源后请记得更新一次仓库

    sudo apt-get update

    # Install the latest version of PostgreSQL.
    # 这里建议你安装一下pgsql-15,在2023往后的五年内,可以得到更好的支持。

    # If you want a specific version, use 'postgresql-15' or similar instead of 'postgresql':

    sudo apt-get -y install postgresql-15

     

    Configuration Steps

    装完就跑?太天真了,还有一小串step等着你配置呢,这个时候没什么user也没什么db

    添加新用户和新数据库新建一个Linux新用户,设置密码

    adduser dbuser


    切换到postgres用户,将在postgres用户下创建新数据库用户:

    sudo su - postgres


    登录数据库: 

    psql


    设置密码:

    \password postgres


    创建数据库用户dbuser(刚才创建的是Linux系统用户),并设置密码:

    CREATE USER dbuser WITH PASSWORD 'password';

    创建用户数据库,这里为exampledb,并指定所有者为dbuser:

    CREATE DATABASE exampledb OWNER dbuser;

    将exampledb数据库的所有权限都赋予dbuser:

    GRANT ALL PRIVILEGES ON DATABASE exampledb to dbuser;


    退出控制台

    \q

     用新用户登陆postgresql

    psql -U dbuser -d bics_pro -h 127.0.0.1 -p 5432

    如果你登陆过程中遇到Postgresql: password authentication failed for user  "postgres"

    sudo -u postgres psql

    Inside the psql shell you can give the DB user postgres a password:

    ALTER USER postgres PASSWORD 'newPassword';

     

    1. # 创建新表
    2. CREATE TABLE user_tbl(name VARCHAR(20), create_time TimeStamp);
    3. # 插入数据
    4. INSERT INTO user_tbl(name, create_time) VALUES('moshow', '2023-09-09');
    5. # 选择记录
    6. SELECT * FROM user_tbl;

    Connect To Pgsql

    Windows下一般推荐Navicat/PgAdmin/DbEaver/DataGrip

    Linux下一般我用PgAdmin或者dbeaver(个人更喜欢,万能的连接工具)/DataGrip

    这里举个例子,大多数工具初次使用都需要下载驱动,或者使用我的DBeaver-Driver-All ( https://github.com/moshowgame/dbeaver-driver-all )整合所有DBeaver的JDBC驱动包,供DBeaver使用,无需每次都搜索和下载,只需clone本项目即可,一个包包含几乎所有的驱动。

    输入完整的登陆信息,数据库(刚才create的BICS_PRO),帐号秘密(dbuser/root123)

    点击测试链接,首次连接需要下载驱动,网速允许的情况下,直接下载即可。或者提前准备好jar包。

    测试成功。

    可以看到我们刚才create的表user_tbl还在

    END! 欢迎大家交流DeepinV20/V23使用心得。

  • 相关阅读:
    「Java开发指南」如何用MyEclipse搭建Spring安全策略?
    利用less实现多主题切换(配合天气现象)
    前k个高频元素_优先队列_java
    Android Studio实现内容丰富的安卓校园超市
    [Servlet 3]会话管理、进阶API、监听过滤器
    数据结构与算法课后题-第六章(图的基本概念)
    人工智能和神经网络区别,人工神经网络有哪几种
    sql server 查询某个字段是否有值 返回bool类型
    OpenCV的应用——快递二维码识别
    linux的常用命令
  • 原文地址:https://blog.csdn.net/moshowgame/article/details/132783034