PostgreSQL生成一个空的20字节gzip压缩备份文件

时间:2018-10-01 22:24:54

标签: postgresql database-backups jelastic

我们在Jelastic中管理多个Java + PostgreSQL环境。我们的PaaS提供商使用Jelastic平台5.4版。

在每种环境中,我们都有一个cron任务,该任务调用Shell脚本以通过pg_dump为PostgreSQL 9.4生成每日压缩的数据库备份。从字面上看,该脚本已经运行了多年,但是最近它停止工作了。脚本如下所示:

#!/bin/bash
DATE=`date +"%Y-%m-%d_%H-%M-%S"`
DB_NAME="my-backup"
FILE="$DB_NAME-$DATE.backup.gz"
BASE_DIR="/var/lib/jelastic/backup"
BACKUP_FILE_PATH=$BASE_DIR/$FILE
pg_dump --verbose --format=custom $DB_NAME | gzip > $BACKUP_FILE_PATH

最近唯一更改的内容与shared_bufferspostgresql.conf值的增加有关,这是我们根据Jelastic提供的指令执行的更改。我们确实尝试将shared_buffers上的更改撤消,以将其恢复为Jelastic环境的默认值,而对备份没有积极影响。

现在,生成的备份文件(压缩)只有20个字节长,整个备份过程比我们期望的要少得多的时间,因为我们的数据库很大(超过1.5GB)并且包含BLOB。从GZIP提取的文件为空。

pg_dump的详细输出中,没有什么异常:

pg_dump: reading schemas
pg_dump: reading user-defined tables
pg_dump: reading extensions
pg_dump: reading user-defined functions
pg_dump: reading user-defined types
pg_dump: reading procedural languages
pg_dump: reading user-defined aggregate functions
pg_dump: reading user-defined operators
pg_dump: reading user-defined operator classes
pg_dump: reading user-defined operator families
pg_dump: reading user-defined text search parsers
pg_dump: reading user-defined text search templates
pg_dump: reading user-defined text search dictionaries
pg_dump: reading user-defined text search configurations
pg_dump: reading user-defined foreign-data wrappers
pg_dump: reading user-defined foreign servers
pg_dump: reading default privileges
pg_dump: reading user-defined collations
pg_dump: reading user-defined conversions
pg_dump: reading type casts
pg_dump: reading table inheritance information
pg_dump: reading event triggers
pg_dump: finding extension members
pg_dump: finding inheritance relationships
pg_dump: reading column info for interesting tables
pg_dump: finding the columns and types of table "databasechangeloglock"
pg_dump: finding the columns and types of table "databasechangelog"
pg_dump: finding the columns and types of table "compania"
pg_dump: finding default expressions of table "compania"
pg_dump: finding the columns and types of table "comprobante"
pg_dump: finding default expressions of table "comprobante"
pg_dump: finding the columns and types of table "estado_comprobante"
pg_dump: finding default expressions of table "estado_comprobante"
pg_dump: finding the columns and types of table "usuario"
pg_dump: finding default expressions of table "usuario"
pg_dump: finding the columns and types of table "clave_contingencia"
pg_dump: finding default expressions of table "clave_contingencia"
pg_dump: finding the columns and types of table "latido_integrador"
pg_dump: finding default expressions of table "latido_integrador"
pg_dump: finding the columns and types of table "comprobante_importado"
pg_dump: finding default expressions of table "comprobante_importado"
pg_dump: finding the columns and types of table "estado_comprobante_importado"
pg_dump: finding default expressions of table "estado_comprobante_importado"
pg_dump: finding the columns and types of table "tarea_comprobante_importado"
pg_dump: finding default expressions of table "tarea_comprobante_importado"
pg_dump: finding the columns and types of table "usuario_compania"
pg_dump: finding default expressions of table "usuario_compania"
pg_dump: flagging inherited columns in subtables
pg_dump: reading indexes
pg_dump: reading indexes for table "databasechangeloglock"
pg_dump: reading indexes for table "compania"
pg_dump: reading indexes for table "comprobante"
pg_dump: reading indexes for table "estado_comprobante"
pg_dump: reading indexes for table "usuario"
pg_dump: reading indexes for table "clave_contingencia"
pg_dump: reading indexes for table "latido_integrador"
pg_dump: reading indexes for table "comprobante_importado"
pg_dump: reading indexes for table "estado_comprobante_importado"
pg_dump: reading indexes for table "tarea_comprobante_importado"
pg_dump: reading indexes for table "usuario_compania"
pg_dump: reading constraints
pg_dump: reading foreign key constraints for table "compania"
pg_dump: reading foreign key constraints for table "comprobante"
pg_dump: reading foreign key constraints for table "estado_comprobante"
pg_dump: reading foreign key constraints for table "usuario"
pg_dump: reading foreign key constraints for table "clave_contingencia"
pg_dump: reading foreign key constraints for table "latido_integrador"
pg_dump: reading foreign key constraints for table "comprobante_importado"
pg_dump: reading foreign key constraints for table "estado_comprobante_importado"
pg_dump: reading foreign key constraints for table "tarea_comprobante_importado"
pg_dump: reading foreign key constraints for table "usuario_compania"
pg_dump: reading triggers
pg_dump: reading triggers for table "compania"
pg_dump: reading triggers for table "comprobante"
pg_dump: reading triggers for table "estado_comprobante"
pg_dump: reading triggers for table "usuario"
pg_dump: reading triggers for table "clave_contingencia"
pg_dump: reading triggers for table "latido_integrador"
pg_dump: reading triggers for table "comprobante_importado"
pg_dump: reading triggers for table "estado_comprobante_importado"
pg_dump: reading triggers for table "tarea_comprobante_importado"
pg_dump: reading triggers for table "usuario_compania"
pg_dump: reading rewrite rules
pg_dump: reading large objects
pg_dump: reading dependency data
pg_dump: saving encoding = UTF8
pg_dump: saving standard_conforming_strings = on
pg_dump: saving database definition

此外,无法在Jelastic上访问的PostgreSQL 9.4日志也没有显示任何相关消息,这些消息可能无法为我们提供线索。

为试图“解决”此问题,我们执行了包括vacuumlovacuumdb --full在内的PostgreSQL维护程序,无济于事。备份文件有足够的可用存储空间,因此这不应成为问题的原因。

关于为什么会发生这种情况的任何想法?我们应该寻找什么,在哪里?由于这是一个至关重要的问题,我们希望您能提出一些建议。

1 个答案:

答案 0 :(得分:1)

您需要做的第一件事是更改文件pg_hba.conf(允许通过套接字进行无密码连接)

CT-42366 ~# cat ./backup.sh 
local    all all                  trust
host     all all     127.0.0.1/32 ident
host     all all     ::1/128      ident
host     all all     0.0.0.0/0    md5

之后,重新启动“ postgresql”服务:

service postgresql restart

然后,如果您对数据库的登录名不同于“ root”,请使用以下修改的脚本:

CT-42366 ~# cat ./backup.sh 
#!/bin/bash
DATE=date +"%Y-%m-%d_%H-%M-%S"
DB_NAME="db_name"
LOGIN="db_login"
FILE="$DB_NAME-$DATE.backup.gz"
BASE_DIR="/var/lib/jelastic/backup"
BACKUP_FILE_PATH=$BASE_DIR/$FILE
pg_dump --user=$LOGIN --format=custom --dbname=$DB_NAME | gzip > 
$BACKUP_FILE_PATH

我们希望这可以帮助您解决问题。