问题标签 [postgresql-9.0]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
postgresql - PostgreSQL函数对当前记录执行一系列操作,然后返回结果
我对PostgreSQL函数和存储过程不熟悉,但是这几天我已经尽力学习了。在这里问之前我很努力。
基本上,我有一种情况,我不能使用简单的 SQL,而函数最有帮助。(那是因为我通过 AJAX 将查询发送到返回 JSONP 的基于 Postgres 的 Web 服务,并且由于查询是基于非预定数量的变量在 JavaScript 中构建的,它可以增长到超过 2000 个左右的 URL 字符MSIE 中允许的限制。)
说,我有一个名为clients的表:
该查询应该返回按列中包含的各种标准排名的客户。列数将来可能会增加。
例如,如果我想获得前 10 个最佳客户,从 100(最好)到 0(最差)排名,SQL 查询将是:
一切都很好,但实际上列数更大(大约 40 个),用户可以立即使用 1 到 15 之间的任何值进行排名。
因此,SQL 路由是不可行的。我尝试创建一个至少可以对值进行标准化的函数:
毫不奇怪,该功能非常缓慢。如果这样使用:
……可以接受。任何涉及订购的东西都会让它慢下来。IE:
有什么方法可以提高上述功能的速度。或者,也许是完全不同的方法?任何帮助将非常感激。谢谢!
更新:
我用最后一个查询运行了 EXPLAIN ANALYZE。为此,我只从整个表中选择了一个样本,因为它花费的时间太长了。我等了10分钟后取消了查询。这是一张有 1000 个客户的桌子:
结果:
sql - 将外键关系限制到相关子类型的行
概述:我试图在数据库中表示几种类型的实体,它们有许多共同的基本字段,然后每个都有一些不与其他类型的实体共享的附加字段。工作流程经常涉及将实体列在一起,所以我决定有一个包含公共字段的表,然后每个实体都有自己的表和附加字段。
实施:所有实体都有一个公共字段“状态”;但是,某些实体仅支持所有可能状态的子集。我还希望每种类型的实体都强制使用其状态子集。最后,我还希望在将实体一起列出时包含该字段,因此将其从公共字段集中排除似乎是不正确的,因为这需要特定类型表的联合,并且 SQL 中缺少“实现接口”意味着列入该领域将是惯例。
为什么我在这里:下面是一个功能性的解决方案,但如果有更好或更常见的方法来解决问题,我很感兴趣。特别是,这个解决方案需要我做一个冗余的unique
约束和一个冗余的状态字段,这让人感觉很不雅。
一些数据:
xml - XML中换行符的正则表达式
我正在拼命地想办法解决这个问题,但没有运气。我正在尝试在 Postgres 中解析这些 XML 数据:
我试图string
在<string>label</string>
. 请注意,我正在使用的 Postgres 版本没有安装 XML (libxml) 函数。
我尝试了许多变体:
substring(xmlStringData from E'<string>label</string>\\n<string>(.*?)</string>')
但没有运气。
java - How to define lock wait time for Postgres 9.0?
I'm performing some tests to evaluate frameworks for our DAO layer. One of the test cases is to replicate a table lock and check how the framework behaves in such situation. This tests are done using Java and mainly JPA, using Hibernate and EclipseLink as JPA vendors, also we're using Hibernate alone and we have a set of interfaces that acts as bridge to the frameworks to ease our tests against any other ORM framework.
I have successfully generated a table lock test case against our MySQL 5.5.11 database, recognized because the application running the test case just got frozen for 50 seconds (default value for lock wait time in MySQL) and then a SQLException related to table lock wait timeout exception appeared in the logs. Then I switched the configuration of the tests to connect to Postgres 9.0 and re executed the test, I could replicate the table lock but now the application just got frozen for 10 minutes, and no exception was thrown, so I have to stop the test execution.
I was searching about how to change this time for Postgres 9.0 and got a result for Postgres 9.3 here: Client Connection Defaults under lock_timeout. Then I checked the documentation for 9.0 and such parameter is not available. Do you know how can I change this in postgres configuration or in my Java client application, probably a JPA or Hibernate or EclipseLink specific configuration just to check the table lock exception from database? The worst scenario is that a table lock appears in production environment and we cannot recover from this unless the application is stopped (which is what we're testing along with the frameworks).
postgresql - Connecting existing data folder in fresh installation
I had to reinstall Postgres x64 9.0.18 on Windows 7 from scratch and I have a full copy of the old data folder. How can I weave the existing database folder into the fresh installation of Pg 9.0.18? When I install over the same directory structure, the install routine recognizes the old data folder but claims that it doesn't contain proper database data. I also tried to start the postgres service with a different data directory (pointing -D to the copy of /data), but it won't start. Can I somehow edit or patch something in order to access my old database? In former versions there was a pg_databases file.
python - 检查 psycopg2/postgresql 中是否存在 python 值列表
我有一个 python 值列表和一个包含特定列的 postgresql 表。我想知道我的 python 列表中的每个元素在表中是否有任何具有该 ID 的行。
例如,假设我有这个 python 列表:
还有那个查询:
给出:
然后我想要一个返回的查询:
我可以遍历列表并为每个值执行一个新的“选择存在”,但我想知道是否有办法在一次调用中做到这一点?
我仅限于 postgresql 9.0
sql - postgresql 查询不会完成
在 postgresl 9.0 上,我们有一个 sql 查询:
这通常需要大约 1.5 秒才能完成。这是解释计划:http ://explain.depesz.com/s/axNN
有时虽然此查询挂起并且不会完成。它甚至可能运行 11 个小时而没有成功。然后它会占用 100% 的 cpu。
此查询使用的唯一锁是“AccessShareLock”,它们都被授予。
该查询作为 java 进程的一部分运行,该进程使用连接池连接到数据库,并按顺序执行这种格式的类似选择查询:
没有更新或删除与此过程并行发生,所以我不认为吸尘可能是这里的问题。在运行整个过程之前(因此在运行 6 个此类查询之前)对所有表进行了分析。
postgres 日志不显示长时间运行的查询的任何条目,因为它们永远不会完成,因此永远不会被记录。
知道什么可能导致这种行为以及如何防止它发生吗?
没有分析的解释计划:
postgresql - Debian Jessie 上的 Postgres 9.0 文件系统级备份
我在 Debian 8.2.0 上并试图从我收到的文件夹中运行 postgres 服务器。版本是 9.0.18。这是我发出的命令:
但光标在终端中一直闪烁。我不确定发生了什么?
谢谢
postgresql - 在 Centos 7 中将 PostgreSQL 9.0 升级到 9.5 不起作用
我们有一个 Postgres 9.0 和 centos 6.2 的环境,并希望迁移到 Postgres 9.5 和 Centos 7.2。
我们用 Centos 7.2 和 Postgres 9.0.23 安装了一个新服务器并恢复了一个数据库备份,它工作得很好。连接工作正常。
然后我们安装 Postgresql 9.5 来运行pg_upgrade
(只是 yum)......我们尝试连接到数据库(9.0)......我们得到......
psql:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接?
我们卸载 postgresql 9.5 并且与数据库的连接再次正常工作:(
任何想法!?
很多。
sql - 一天内每小时的表格条目总数
我有一个表mytable
,其中包含一个名为 evtime 的事件时间字段。为了总结每天的条目数,我使用:
这很好用。但是现在,对于某个特定日期,我想查看每小时的总数。