获取 Postgres 数据库的编码
我有一个数据库,我需要知道数据库的默认编码。我想从命令行获取它。
I have a database, and I need to know the default encoding for the database. I want to get it from the command line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
从命令行:
从
psql
、SQL IDE 或 API 中:From the command line:
From within
psql
, an SQL IDE or an API:方法 1:
如果您已经登录到数据库服务器,只需复制并粘贴此内容。
结果:
对于客户端编码:
方法 2:
如果您已经登录,请再次使用此方法获取基于列表的结果
Method 1:
If you're already logged in to the db server, just copy and paste this.
Result:
For Client encoding :
Method 2:
Again if you are already logged in, use this to get the list based result
程序化解决方案:
A programmatic solution:
如果你想获取数据库编码:
你会看到类似的内容:
If you want to get database encodings:
You'll see something like:
tl;dr
标准方式:
information_schema
来自 SQL 标准架构 <每个数据库/目录中都存在 href="https://www.postgresql.org/docs/current/static/information-schema.html" rel="noreferrer">
information_schema
,使用名为character_sets
的已定义视图。这种方法应该可以跨所有标准数据库系统移植。尽管名称是复数,但它仅显示一行,报告当前数据库/目录。
第三列是
character_set_name
:tl;dr
Standard way:
information_schema
From the SQL-standard schema
information_schema
present in every database/catalog, use the defined view namedcharacter_sets
. This approach should be portable across all standard database systems.Despite the name being plural, it shows only a single row, reporting on the current database/catalog.
The third column is
character_set_name
:因为给猫剥皮的方法不止一种:
显示所有数据库名称、编码等。
Because there's more than one way to skin a cat:
Shows all the database names, encoding, and more.
获取服务器编码的另一种方法(参见 https://pgpedia.info/s/server_encoding.html< /a>):
还可以使用类似的选择来获取其他设置,例如“client_encoding”。
Another way of getting the server encoding (described at https://pgpedia.info/s/server_encoding.html):
One can also use a similar select to get other settings, e.g. 'client_encoding'.