gpt4 book ai didi

postgresql - 如何使用带有 createdb 和 URI 的终端?

转载 作者:行者123 更新时间:2023-11-29 13:45:48 25 4
gpt4 key购买 nike

URI connection-string可以这么复杂,这里有一个标准的例子:

  createdb "postgresql://postgres:postgres@localhost:5432/sandbox"

当然,它不适用于 createdb(“template1:​​FATAL”),这就是问题所在。 URI 与 psql 一起工作正常,例如。

  psql "postgresql://postgres:postgres@localhost:5432/postgres"

我正在寻找具有预期行为的任何东西,无论命令的名称是否不是 createdb


PS1:在我的环境中。即使对于 postgres 用户,也有密码等,我所有的脚本都使用 URI connection-string 标准,不再有 -U 等。选项。这个问题的重点是URI标准。使用现代客户端和连接,v9+。

PS2:作为它的传统和理念,我们期待orthogonal behaviour在 PostgreSQL 提供的命令中。 psqlpg_dump 关于 URI 是正交的; psqlpg_dumpcreatedb-U 选项正交...我预计 URI 使用有一些正交性...
或者存在架构错误

最佳答案

clusterdb、createdb、createuser、dropdb、dropuser、reindexdb 和 vacuumdb 是实用命令,它们是 SQL 命令的包装器。虽然没有正式弃用,但它们在任何人关心的程序列表中并不靠前。如今,大多数人都使用某种脚本来完成他们所做的事情。如果您想使用客户端程序和 URI 来执行 CREATE DATABASE,那么:

psql "postgresql://postgres:postgres@localhost:5432/postgres" -c 'CREATE DATABASE my_test_db'
Null display is "NULL".
CREATE DATABASE

或者传入一个文件使用:

psql "postgresql://postgres:postgres@localhost:5432/postgres" -f db_create.sql

2020 年 12 月 5 日更新

似乎有一个未记录的功能现在已经公开。对于大多数这些命令(不是 *user),有一个 --maintenance-db 选项。来自 CREATEDB开发文档:

--maintenance-db=dbname

Specifies the name of the database to connect to when creating the new database. If not specified, the postgres database will be used; if that does not exist (or if it is the name of the new database being created), template1 will be used. This can be a connection string. If so, connection string parameters will override any conflicting command line options.

其中连接字符串可以是 URI

关于postgresql - 如何使用带有 createdb 和 URI 的终端?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48731698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com