小编Gon*_*uez的帖子

ALTER TABLE 上的数据库“冻结”

我们的生产环境今天早上在更改表时冻结*了一段时间,实际上是添加了一列。

违规 SQL:ALTER TABLE cliente ADD COLUMN topicos character varying(20)[];

* 登录到我们的系统需要从同一张表中进行选择,因此在更改表期间没有人可以登录。我们实际上不得不终止进程以让系统恢复正常运行。


表结构:

CREATE TABLE cliente
(
  rut character varying(30) NOT NULL,
  nombre character varying(150) NOT NULL,
  razon_social character varying(150) NOT NULL,
  direccion character varying(200) NOT NULL,
  comuna character varying(100) NOT NULL,
  ciudad character varying(100) NOT NULL,
  codigo_pais character varying(3) NOT NULL,
  activo boolean DEFAULT true,
  id serial NOT NULL,
  stock boolean DEFAULT false,
  vigente boolean DEFAULT true,
  clase integer DEFAULT 1,
  plan integer DEFAULT 1,
  plantilla character varying(15) …
Run Code Online (Sandbox Code Playgroud)

postgresql alter-table blocking postgresql-9.4

23
推荐指数
2
解决办法
2万
查看次数

PostgreSQL:SSL SYSCALL 错误:检测到 EOF

首先,我搜索并找到了几篇与此错误相关的帖子,其中大多数都指向 RAM 问题或 SSL 问题,我尝试通过在命令行中添加 sslmode=disabled 来克服 SSL 的可能性:

 psql -U waypoint -d waypoint -W -c "alter table telemetria_data.historico alter clase type smallint, alter valor type real[], alter power type smallint, alter voltaje type real;" -h localhost -v sslmode=disable
Run Code Online (Sandbox Code Playgroud)

但同样的消息出现了:

SSL SYSCALL error: EOF detected
connection to server was lost
Run Code Online (Sandbox Code Playgroud)

关于可能的内存问题,我不知道如何解决。

数据结构是这个问题中描述的数据结构,正如您可能发现的那样,这将是一个非常长的运行查询,以完成对所有继承表的完整更改表。

操作系统:

Linux ip-10-1-0-9 3.16.0-4-amd64 #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

PostgreSQL:

PostgreSQL 9.4.9 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
Run Code Online (Sandbox Code Playgroud)

更新 2017-06-01 13:50 …

postgresql aws postgresql-9.4

13
推荐指数
1
解决办法
3万
查看次数

查找未使用的索引

我使用以下查询来查找未使用的索引:

SELECT 
PSUI.indexrelid::regclass AS IndexName 
,PSUI.relid::regclass AS TableName 
FROM pg_stat_user_indexes AS PSUI 
JOIN pg_index AS PI 
ON PSUI.IndexRelid = PI.IndexRelid 
WHERE PSUI.idx_scan = 0 
AND PI.indisunique IS FALSE;
Run Code Online (Sandbox Code Playgroud)

在运行之前我应该​​运行任何统计收集语法或其他任何内容吗?上述查询可以用于此目的吗?我的意思是,那么 SQL 输出中显示的所有索引都应该被删除吗?

这是一个已有 8 年历史的 BD,因此结果行可能实际上是遗留下来的,我想应该有足够的统计数据,以便告诉在哪里使用 和 。

postgresql index index-tuning postgresql-9.4

9
推荐指数
2
解决办法
5707
查看次数

org.postgresql.util.PSQLException:错误:由于与恢复冲突而取消语句

我目前有一个 PostgreSQL 从属节点存在问题,但在主节点中不会出现这些问题。似乎与节点同步过程有关。

完整的堆栈跟踪:

org.postgresql.util.PSQLException: ERROR: canceling statement due to conflict with recovery
  Detail: User query might have needed to see row versions that must be removed.
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2103)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1836)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:512)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:388)
    at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:273)
    at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
    at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
    at cl.waypoint.mailer.reportes.BasicReport.getSingleColumn(BasicReport.java:542)
    at cl.waypoint.mailer.reportes.BasicReport.getSingleColumn(BasicReport.java:518)
    at cl.waypoint.mailer.reportes.StatusSemanalClientes.updateIgnicion(StatusSemanalClientes.java:448)
    at cl.waypoint.mailer.reportes.StatusSemanalClientes.access$2(StatusSemanalClientes.java:447)
    at cl.waypoint.mailer.reportes.StatusSemanalClientes$TempAndDoorLocator.call(StatusSemanalClientes.java:414)
    at cl.waypoint.mailer.reportes.StatusSemanalClientes$TempAndDoorLocator.call(StatusSemanalClientes.java:1)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
Run Code Online (Sandbox Code Playgroud)

数据库版本:

PostgreSQL 9.4.9 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
Run Code Online (Sandbox Code Playgroud)

操作系统版本:

Distributor ID: …
Run Code Online (Sandbox Code Playgroud)

postgresql data-synchronization postgresql-9.4 master-slave-replication

3
推荐指数
1
解决办法
5977
查看次数

错误:“sql”不是已知变量

这一定是我在这里问过的最愚蠢的问题之一,但是我的 SQL 脚本中肯定隐藏着一些非常恶心的问题,阻止它运行。

我正在使用以下示例 CLI 语法调用 cobertura.sql 文件:

psql -h localhost -U myUser -f cobertura.sql myDB
Run Code Online (Sandbox Code Playgroud)

但它抱怨以下错误:

psql:cobertura.sql:29: ERROR:  "sql " is not a known variable
LINE 14: sql := format('insert into cobertura_tmp select count(*) as ... cobertura.sql file:
Run Code Online (Sandbox Code Playgroud)
DO language plpgsql $$
declare 
    eq  record;
    sql varchar;
BEGIN

create table if not exists cobertura_tmp  (num integer, realtime char(1), lat numeric, lng numeric);

truncate table cobertura_tmp;
for eq in select imei_equipo as imei  from cliente_avl_equipo where id_cliente in (select id …
Run Code Online (Sandbox Code Playgroud)

postgresql scripting plpgsql postgresql-9.4 unicode

3
推荐指数
1
解决办法
4757
查看次数

发现丢失的外键和/或索引

我们有一个相当大的数据库(大约700GB的数据),这是我们继承的,并且有几个DBA。随着时间的推移,我们意识到有几个丢失的外键和索引。

我想知道是否有某种自动方法可以使用某种日志解析或类似的方法来发现此类潜在丢失的键/索引。

postgresql index foreign-key database-design

2
推荐指数
1
解决办法
2812
查看次数

事后分析:PostgreSQL 复制失败

我们有一个 PostgreSQL 9.4.9 生产服务器,它正在复制到一个从属实例,但今天我发现该实例不同步!

显而易见的操作是重新创建从属节点,为复制活动设置指标和适当的警报,因此我们可以有效地监控主节点和从属节点之间的同步状态。

但是,由于同步失败,我想首先诊断问题并尝试确定其根本原因,因为这将是大约 6 个月内第二次发生这种情况。

问题:如何诊断复制过程中失败的内容,以便这次可以以更好的方式完成?

版本说明:

PostgreSQL 9.4.9 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit
Run Code Online (Sandbox Code Playgroud)

从从节点,在/var/log/postgresql/postgresql-9.4-main.log我可以看到:

2017-07-18 19:43:55 UTC [12816-1] LOG:  started streaming WAL from primary at 125D/68000000 on timeline 1
2017-07-18 19:43:55 UTC [12816-2] FATAL:  could not receive data from WAL stream: ERROR:  requested WAL segment 000000010000125D00000068 has already been removed

2017-07-18 19:44:00 UTC [12817-1] LOG:  started streaming WAL from primary at 125D/68000000 on timeline 1 …
Run Code Online (Sandbox Code Playgroud)

postgresql replication data-synchronization postgresql-9.4 master-slave-replication

2
推荐指数
1
解决办法
2406
查看次数