• Ubuntu18.04 安装Postgresql12



    Postgresql 12 是有很多新增特性的,但是最关键的一点是Postgresql 12 的SQL备份文件是不能直接使用psql命令导入到Postgresql 10 的。


    Ubuntu18.04 默认的安装方式 apt install postgresql 安装的是 postgresql 10,这就导致了数据库恢复的时候会出现一些麻烦。

    可以先移除已经安装的 pg10

    sudo apt-get --purge remove postgresql*

     建议先期增加阿里源 避免 下载不到 其他的依赖的包

    mv /etc/apt/sources.list
    
    cat << EOF >/etc/apt/sources.list
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    EOF

    所以,最好选择一步到位安装postgresql 12.
    Ubuntu 20.04 上面使用 apt install postgresql 默认安装的就是Postgresql 12 了。ubuntu18.04 需要进行部分处理.

    安装命令
    # 添加 Postgresql 源到系统源
    sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
    
    # 添加签名密钥
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
    
    # 更新软件包列表
    # 在此之前可以先将软件源更换为国内的软件源
    sudo apt-get update
    
    # 安装最新版本的 PostgreSQL
    # 如果想要指定版本的话,使用 postgresql-12 
    sudo apt-get install postgresql-12 postgresql-contrib
    # 注意需要安装这个contrib 才可以使用 uuid 等函数.

    注意查看服务信息

    systemctl |grep postgres

    发现 ubuntu与centos的服务名不太一样

    可以查看 postgresql@12-main 的服务 修改配置文件 并且设置开机启动等.

    有一点比较好的是 不需要想rpm安装时 还需要进行一次 initdb的操作

    注意设置开机启动的命令也比较简单:

    systemctl enable postgresql@12-main
    即可.

    修改数据库的字符集

    注意 默认安装的是 latin1 的字符集 可能不符合产品的需求
    需要进行处理
    
    root 用户下
    systemctl stop postgresql@12-main
    rm -rf /var/lib/postgresql/12/main/*
    
    su - postgres 重建数据库
    cd /usr/lib/postgresql/12/bin
    export LANG=en_US.UTF-8
    ./initdb -D /var/lib/postgresql/12/main -E UTF8
    
    然后重启数据库
    
    systemctl restart postgresql@12-main
    
    注意需要修改 pg_hba.conf 以及 postgresql.conf 的配置文件.
    建议 localhost 可以trust 访问. 其他ip地址 至少 md5访问
    
    修改管理员密码
    su - postgres
    psql
    alter user postgres with password 'Test20131127' ;
        

    部分学习自:

    https://blog.csdn.net/qq_36963372/article/details/107658420

  • 相关阅读:
    groovy的效率问题
    强大的模板引擎开源软件NVelocity
    每个人应该知道的NVelocity用法
    NVelocity语法常用指令
    CS0016: 未能写入输出文件“c:WINDOWSMicrosoft.NETFramework.。。”--“拒绝访问
    C# 数组基础知识
    c#中的 数组
    网络编程之webclient和httpwebrequest的使用
    HttpWebRequest和WebClient的区别
    C#如何使用SplitContainer控件实现上下分隔
  • 原文地址:https://www.cnblogs.com/jinanxiaolaohu/p/15524889.html
Copyright © 2020-2023  润新知