通过命令行连接flexusrds for postgresql实例-九游平台
操作场景
flexusrds for postgresql实例购买完成后,可以先登录到flexus云服务器x实例,在flexus云服务器x实例上安装postgresql客户端,然后通过psql命令行连接到实例。
通过客户端连接flexusrds for postgresql实例(15及以下版本)
- 登录与flexusrds实例在同一区域下的flexus云服务器x实例。
- 安装postgresql客户端。
postgresql社区提供了针对不同操作系统的。通过操作系统的安装工具直接下载安装。此安装方式比较简单,但是对ecs操作系统有要求,只有postgresql社区中支持的操作系统才可以使用该安装方式。
使用操作系统默认安装,当前使用的linux操作系统是centos 7,通过工具安装最高版本是15版本。
图1 获取安装工具执行安装命令:
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 postgresql15-server
查看是否安装成功:
psql -v
图2 安装成功 - 在flexus云服务器x实例上执行以下命令连接flexusrds for postgresql实例。
psql --no-readline -u<user>-h<host>-p<port>-d<datastore>-w
示例:
psql --no-readline -u root -h 192.168.0.44 -p 5432 -d postgres -w表1 参数说明 参数
说明
<host>
- 内网连接(推荐):单击实例名称,在“概览”页面获取的内网地址。
- 公网连接:单击实例名称,在“概览”页面获取的弹性公网ip。绑定弹性公网ip的操作,请参见flexusrds for postgresql实例绑定和解绑弹性公网ip。
使用弹性公网ip连接数据库实例时,必须要将弹性公网ip和5432端口加入安全组“sg-default-smb”的入方向规则。具体操作,请参见添加安全组规则。
说明:flexus云服务器x实例和flexusrds for postgresql实例在同一区域、同一vpc下时,推荐使用内网连接,安全性更高。
不能通过内网地址访问flexusrds for postgresql实例时,使用公网访问。
5432。
<user>
root。
<datastore>
postgres。
- 出现如下提示时,输入root账号对应的密码。
enter password:
通过源码连接flexusrds for postgresql实例(对版本没有限制)
- 登录与flexusrds实例在同一区域下的flexus云服务器x实例。
- 安装postgresql客户端。
,该安装方式对rds for postgresql实例的版本以及ecs的操作系统没有限制。
下面以huawei cloud euleros 2.0镜像的ecs为例,安装postgresql 16.4版本客户端。
图3 查看ecs镜像- 要支持ssl,需要在ecs上提前下载openssl。
sudo yum install -y openssl-devel
- 在获取代码下载链接,使用wget直接下载安装包或者下载到本地后上传到ecs上。
wget https://ftp.postgresql.org/pub/source/v16.4/postgresql-16.4.tar.gz
- 解压安装包。
tar xf postgresql-16.4.tar.gz
- 编译安装。
cd postgresql-16.4 ./configure --without-icu --without-readline --without-zlib --with-openssl make -j 8 && make install
不指定--prefix,表示默认路径为“/usr/local/pgsql”,因为只安装客户端采用最简安装。
图4 编译安装 - 配置环境变量,在“/etc/profile”文件中添加以下内容。
export path=/usr/local/pgsql/bin:$path export ld_library_path=/usr/local/pgsql/lib:$ld_library_path source /etc/profile
- 测试psql是否可使用。
psql -v
图5 测试psql可用
- 要支持ssl,需要在ecs上提前下载openssl。
- 在flexus云服务器x实例上执行以下命令连接flexusrds for postgresql实例。
psql --no-readline -u<user>-h<host>-p<port>-d<datastore>-w
示例:
psql --no-readline -u root -h 192.168.0.44 -p 5432 -d postgres -w表2 参数说明 参数
说明
<host>
- 内网连接(推荐):单击实例名称,在“概览”页面获取的内网地址。
- 公网连接:单击实例名称,在“概览”页面获取的弹性公网ip。绑定弹性公网ip的操作,请参见flexusrds for postgresql实例绑定和解绑弹性公网ip。
使用弹性公网ip连接数据库实例时,必须要将弹性公网ip和5432端口加入安全组“sg-default-smb”的入方向规则。具体操作,请参见添加安全组规则。
说明:flexus云服务器x实例和flexusrds for postgresql实例在同一区域、同一vpc下时,推荐使用内网连接,安全性更高。
不能通过内网地址访问flexusrds for postgresql实例时,使用公网访问。
5432。
<user>
root。
<datastore>
postgres。
- 出现如下提示时,输入root账号对应的密码。
enter password:
相关文档
意见反馈
文档内容是否对您有帮助?
如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨