暂无图片
暂无图片
暂无图片
暂无图片
暂无图片
PostgreSQL元命令之connect_20191216
981
3页
3次
2019-12-16
5墨值下载
前言:今年十月份刚参加完PG分会组织的第一场线上考试,也是想测
试下自己。考题范围还挺全挺细的,有架构体系方面,有深入源码方
面,也有考到工作中一些常见用法的其他方式,如启动数据库的方式
等。现在还有印象的一道关于元命令\c[onnect],下面详细介绍一下不
同参数使用方式:
1.常见psql连接数据库
1 $psql‐h127.0.0.1‐Upostgrespostgres
2 psql(12.1)
3 Type"help"forhelp.
4
5 postgres=#\conninfo
6 Youareconnectedtodatabase"postgres"asuser"postgres"onh
ost"127.0.0.1"atport"5432".
7 postgres=#
使用元命令\conninfo可以查看数据库连接信息,包括主机、端口、数据库名
称、数据库用户
2.同一用户切换到其他数据库
1 test=#\connecttest
2 Youarenowconnectedtodatabase"test"asuser"postgres".
当前登录用户为postgres,登录用户不变,切换到test数据库
3.同一库切换登录用户
1 test=#\connect‐test
2 Passwordforusertest:
3 Youarenowconnectedtodatabase"test"asuser"test".
当前数据库为test,数据库不变,登录用户由postgres切换到test
单独切换用户,需要加“-”
4.当前实例同时切换数据库和登录用户
1 test=>\conninfo
2 Youareconnectedtodatabase"test"asuser"test"viasocketi
n"/var/run/postgresql"atport"5432".
3 test=>\connectpostgrespostgres
4 Youarenowconnectedtodatabase"postgres"asuser"postgres".
5 postgres=>
当前数据库为test,登录用户为test,切换数据库为postgres,且切换登录用户
为postgres
5.切换主机和数据库
1 $psql‐Upostgres
2 psql(12.1)
3 Type"help"forhelp.
4
5 postgres=#\conninfo
6 Youareconnectedtodatabase"postgres"asuser"postgres"via
socketin"/var/run/postgresql"atport"5432".
7
8 postgres=#\connecttest‐192.168.99.200
9 Youarenowconnectedtodatabase"test"asuser"postgres"onh
ost"192.168.99.200"atport"5432".
主机参数前面需要加“-”
6.切换主机、数据库和登录用户(端口为默认)
1 $psql‐Upostgres
2 psql(12.1)
3 Type"help"forhelp.
4
5 postgres=#\conninfo
6 Youareconnectedtodatabase"postgres"asuser"postgres"via
socketin"/var/run/postgresql"atport"5432".
7
8 postgres=#\connecttesttest192.168.99.200
of 3
5墨值下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜