商道如狼道 发表于 2024-12-10 08:13:01

PostgreSQL 的登陆方式(当地和长途)

        本次分享一下PostgreSQL 的登陆方式,当地登录和长途登录,今天就展开讲一下。
当地登录:

        假如看了我的第一篇PostgreSQL安装,在末尾的时候为了方便大家操作(启动、关闭、登录)PostgreSQL,我这边写了几个参数可以检察一下
https://i-blog.csdnimg.cn/direct/e8b34d5bf061402d93244757898c59df.png
假如没有设置,可以看一下上篇文章,直接看末了就行:
全网最细PostgreSQL在Linux下安装全过程(源码编译安装)_pgsqllinux下载安装-CSDN博客
这样当地登录就很简单了,只需要在命令行上输入
$ pglg
psql (15.1)
Type "help" for help.

postgres=# \l
                                                 List of databases
   Name    |Owner   | Encoding |   Collate   |    Ctype    | ICU Locale | Locale Provider |   Access privileges

-----------+----------+----------+-------------+-------------+------------+-----------------+----------------------
-
postgres| postgres | UTF8   | en_US.UTF-8 | en_US.UTF-8 |            | libc            |
template0 | postgres | UTF8   | en_US.UTF-8 | en_US.UTF-8 |            | libc            | =c/postgres         
+
         |          |          |             |             |            |               | postgres=CTc/postgres
template1 | postgres | UTF8   | en_US.UTF-8 | en_US.UTF-8 |            | libc            | =c/postgres         
+
         |          |          |             |             |            |               | postgres=CTc/postgres
text_db   | osdba    | UTF8   | en_US.UTF-8 | en_US.UTF-8 |            | libc            |
(4 rows)
那可以给大家表明一下的就是设置参数简单登录是为了方便,便于大家理解,可以展开讲一下
我们正常登录pg的命令是:
psql -d postgres -p 5432 -U 用户名(默认postgres)
-W 密码 (当地不消设置,设置以后长途登录需要密码)设置密码的命令:
postgres=# alter user postgres with password 'pg123';
ALTER ROLE -h 数据库IP(默认当地登录)
-p 数据库端口(默认5432)生产情况需要更改默认端口
-d 需要访问的数据库名称(默认postgres库)
-L 输出日志的路径
这些上面都是一些具体的参数,供大家相识。
长途登录:

首先先修改pg_hba.conf文件
vi /home/postgres/pgdata/pg_hba.conf https://i-blog.csdnimg.cn/direct/1021df2ca8b74e0d9556b8016b45ae0e.png 添加末了一行:host all all 0/0 md5
对用户的密码进行scran - sha -256或MD5验证,需要输入密码。
修改postgresql.conf文件(PG数据库的参数文件)
vi/home/postgres/pgdata/postgresql.conf https://i-blog.csdnimg.cn/direct/aec7212724f54408a7f1764f43e6ddd0.png
把数据库重启,使参数生效!
创建一个可以用户,便于长途登陆:
create user test with password 'test123';
create database testdb with encoding='utf8' owner=test;
grant all privileges on database testdb to test;
https://i-blog.csdnimg.cn/direct/1df0f6db9247430f925d98ebb7b36026.png
接下来我们就可以用长途登录图形化界面登录了,图形化工具有很多种,下一章节回重点讲PG的图形化工具,现在为了方便演示,我们就以PG官方的图形化工具PGAdmin来做演示,下面连接是下载所在,我下载的是windows版本
PostgreSQL: File Browserhttps://csdnimg.cn/release/blog_editor_html/release2.3.7/ckeditor/plugins/CsdnLink/icons/icon-default.png?t=O83Ahttps://www.postgresql.org/ftp/pgadmin/pgadmin4/v8.13/windows/安装部署实在很简单,但是为了表现全网最细,我还是截图说一下吧!会安装的跳过
https://i-blog.csdnimg.cn/direct/1589031f882a48b9911c73cbf3a8764a.png
https://i-blog.csdnimg.cn/direct/49cd73d03ada47a0a38786fb7097c1fb.png
选择目录
https://i-blog.csdnimg.cn/direct/1238a34f943c4fd7a3ddb445b8283cf7.png
创建快捷方式,我选择不创建,各位看自己的需求都可以
https://i-blog.csdnimg.cn/direct/9baec9d5ab4a45ee9c089f6eb0f14b57.png
安装 
https://i-blog.csdnimg.cn/direct/0108405e5d574c7c83278cf38871fd88.png
这一步重点 记得看看自己需不要重启电脑,假如不需要牢记选择第二个
https://i-blog.csdnimg.cn/direct/1f61f9ac400f4f0795495d8097439f7b.png
启动之后
https://i-blog.csdnimg.cn/direct/96afc0e61cc04264ae9e172f34d50d2b.png
起一个名字 pgtext
https://i-blog.csdnimg.cn/direct/2a468e52ec184447b29ec29d64a8d778.png
填写对应信息主机IP 端标语 等
https://i-blog.csdnimg.cn/direct/f0aee3193527440eb32c72b2b5d8eb8e.png
登录成功
https://i-blog.csdnimg.cn/direct/8424e39ebc734817b7c816ed83d522c5.png
这就是长途登录pg的此中一种方式,下一章,我就会写几个关于pg图形化工具的演示!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: PostgreSQL 的登陆方式(当地和长途)