哪个DB连接到更高级别的应用程序管理其他数据库(Which DB to connect to for higher level application managing other database)

系统教程 行业动态 更新时间:2024-06-14 16:57:40
哪个DB连接到更高级别的应用程序管理其他数据库(Which DB to connect to for higher level application managing other database)

我有一个应用程序,将创建和删除postgres数据库。 应用程序本身有自己的sql server数据库。 有点怪异的建筑,但它不是选择。

我对如何连接到postgres服务器以执行这些create table和drop table命令感到有点困惑。 通常在app.config或web.config ,连接字符串将指定数据库。 在这种情况下,我只想指定服务器。

查询可以直接运行到postgres服务器,没有特定的数据库吗?

我应该使用服务器创建的postgres数据库吗? 我试过这个... select * from pg_database然后从第一个查询中drop database DBNAME ,并且它给出了一个错误,说数据库不存在。

或者我可以创建一个空数据库来连接并向其提交查询,尽管它没有用于任何事情。

I have an application that will be creating and dropping postgres databases. The application itself has its own sql server database. Kind of a bizarre architecture but it's not by choice.

I'm a little confused on how I should connect to the postgres server to execute these create table and drop table commands. Normally in an app.config or web.config, the connection string would specify the database. In this case, I just want to specify the server.

Can queries be run directly to a postgres server, without a particular database?

Should I use the postgres database that was created by the server? I tried this... select * from pg_database and then drop database DBNAME with a result from the first query, and it gave an error saying the database does not exist.

Or I could create an empty database to connect to and submit the queries to it, despite it not being used for anything.

最满意答案

您可以连接到postgres数据库,然后从那里运行drop database <DBNAME> ,是的。 另一种选择是,例如, template1 。 (我会避免使用template0,因为它本质上是创建template1的根模板,如果发生了某些事情,你总是可以从template0快速重新创建template1 ,假设你没有修改template1而不是template0 。)

我经常连接到postgres ,我自己,用于服务器级命令。

我跑了DROP DATABASE droptest; 在创建一个空数据库并看到它从pg_database查询返回后通过psql ,所以一般来说肯定是有效的。

也许它在某种程度上通过其他过程在你查询事物和你完成DROP...之间的过程中被删除了。

另一种选择是改为命令行工具dropdb 。 这是drop database的包装器,也是我通常用于手动和自动数据库丢弃实例的东西。

You could connect to the postgres database and then run drop database <DBNAME> from there, yes. Another option would be, say, template1. (I would avoid template0 since that's essentially the root template from which template1 was created, and you could always recreate template1 quickly from template0 if something happened to it, assuming you haven't modified template1 but not template0.)

I usually connect to postgres, myself, for server-level commands.

I ran DROP DATABASE droptest; via psql after creating an empty database and seeing it returned from a pg_database query, so that definitely works in general.

Perhaps it was somehow deleted via some other process in the interim between when you queried things and when you did the DROP....

Another option would be to shell out to the command line tool dropdb instead. This is a wrapper around drop database and is what I generally use both for manual and automated instances of database drops.

更多推荐

本文发布于:2023-04-13 12:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/16bd6bf292236655d0d0f32b33355716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:连接到   应用程序   高级   数据库   DB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!