use postgres in entgo

postgres 创建用户,创建库

create user aca with password '';
create database hwapi owner 'aca'; 

在postgresql.conf 中开启

listen_addresses = '*'

在pg_hba.conf 中允许认证方式,

# TYPE  DATABASE  USER  CIDR-ADDRESS  METHOD
host  all  all 0.0.0.0/0 md5

重启postgres生效。

ent里面连接pg

_ "github.com/lib/pq"

client, err := ent.Open("postgres",
	"host=127.0.0.1 port=5432 user=aca dbname=yy password=xxx sslmode=disable")

感觉跟mysql差不多。

pg centos7 安装

sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql16-server
sudo /usr/pgsql-16/bin/postgresql-16-setup initdb
sudo systemctl enable postgresql-16
sudo systemctl start postgresql-16

centos7好像装不了16,15即可,自带的版本会比较低,不推荐。

posted @ 2024-02-01 08:52  过去的我  阅读(9)  评论(0编辑  收藏  举报