Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
problema con la creación de base de datos si no existe a través de la herramienta de copia de seguridad y restauración de postgres

Escribí un script bat para ejecutar la herramienta de copia de seguridad y restauración de Postgres.

Tengo un pequeño problema con el flujo de restauración: funciona bien mientras exista mi base de datos. Pero si no, fallará. Mi comando de restauración:

"pg_restore.exe" -d postgres://postgres:1234@127.0.0.1:9195/mydb -w -c -v -F c --if-exists "DatabaseBackup_mydb.tar" 2>> "DatabaseRestore_mydb.log"

Entonces necesito modificar ese comando de alguna manera que manejará también un caso de uso en el que la base de datos "mydb" no existe, y crearla en tal caso.

simplemente agregar el indicador -C no funcionará en ese caso.

¿Cualquier sugerencia?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debería funcionar usando postgres://postgres:1234@127.0.0.1:9195/postgres y agregando -C . Obviamente prueba en instancia desechable. Esto se conectará a la base de datos de postgres DROP DATABASE IF EXISTS mydb; , luego CREATE DATABASE mydb , conéctese a mydb y luego restaure los objetos de la base de datos.

Demostrar:

 \l test_db List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ------+-------+----------+---------+-------+------------------- (0 rows) pg_restore -d postgres -c -C -U postgres test_db.out pg_restore: while PROCESSING TOC: pg_restore: from TOC entry 4734; 1262 1170111 DATABASE test_db postgres pg_restore: error: could not execute query: ERROR: database "test_db" does not exist Command was: DROP DATABASE test_db; pg_restore: warning: errors ignored on restore: 1 \l test_db List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ---------+----------+----------+-------------+-------------+------------------- test_db | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (1 row) pg_restore -d postgres -c -C -U postgres test_db.out \l test_db List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges ---------+----------+----------+-------------+-------------+------------------- test_db | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | (1 row)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!