How to connect public schema to restore backup in pgAdmin4 - postgresql

I am trying to restore a postgresql database backup file of power outage information sent by a work colleague and keep running into an error. They sent a file with a .backup extension and said "it should restore to the public schema of an empty postgresql database". I am using pgAdmin 4 and following the steps suggested here https://o7planning.org/11913/backup-and-restore-postgres-database-with-pgadmin to restore the database of
creating a new empty database
right clicking on the new database and clicking restore
linking to file path of backup and running
however, each time I get the error
pg_restore: error: could not execute query: ERROR: schema "outage_data" does not exist
Not sure how to solve it. Any help would be greatly appreciated!
(Not sure if it is important but I am running on Windows 10 and pgAdmin4 version 6)

Do you get more errors after that? This might be a harmless error.
For example, if a table in "public" references a table in "outage_data", but only public was dumped, then you will get this error when it tries to recreate the foreign key constraint. That constraint of course will be missing, but no other harm is done. The public table and all of its data will still be there.

Related

DROP ROLE IF EXISTS fails with an "does not exist" error, instead of a NOTICE

A set of 20 month old new DB provisioning .sql files suddenly stopped working on our PostGRES 12.7 instance hosted on the IBM Cloud. Every DROP ROLE IF EXISTS clause now fails with an ERROR, where previously it would give notice and continue with configuration, even if run on a new, empty database.
The exact commands:
DROP ROLE IF EXISTS "anonymous";
or
DROP ROLE IF EXISTS "FLUMMOXED";
return
ERROR: role "FLUMMOXED" does not exist
SQL state: 42704
instead of a NOTICE.
What I've tried:
I've been through the PostGRES manual, and this command hasn't changed since PostGRES 8.
I've read through the other posts, which emphasize sensitivity to casing.
I've checked the 12.8 upgrade log, and this command isn't mentioned.
I've tried the command on an empty, new DB, and it fails there as well.
Has anyone seen this before?
Thanks.

Linking Access tables into a PostgreSQL Database using a foreign data wrapper

I'm new to postgres so this problem is probably a relatively easy one for someone else. However, I have spent many frustrating hours trying to figure out the solution. I have an Access Database of metadata that must be kept updated for sending records to other groups. I also have a database using PostgreSQL and PGAdmin which also has these same metadata tables. Currently these tables in the Postgres database get updated manually by exporting the Access tables as excel files, and then importing them into the SQL tables. It's not the most efficient process and could lead to errors in the SQL database if someone forgets to check before running any queries that they are using the most recent data from Access. So I would like to integrate some of the tables from my Access database with my Postgres database.
Originally I tried just installing drivers to export the Access tables directly to Postgres which worked, but not in the way that I wanted since it just brings in a table which I would still need to manually update. From my understanding, I can create a server connection in postgres to access and that would then bring in updated data using a foreign data wrapper.
I tried to use ogr_fdw.
CREATE EXTENSION ogr_fdw;
When I try:
CREATE SERVER metadata
FOREIGN DATA WRAPPER ogr_fdw
OPTIONS (
datasource 'H:\Databases\20170712.accdb',
format 'ODBC' );
I receive: ERROR: unable to connect to data source "H:\Databases\20170712.accdb"
SQL state: HV00D
When I try:
CREATE SERVER metadata
FOREIGN DATA WRAPPER ogr_fdw
OPTIONS (
datasource 'H:\Databases\20170712.accdb',
format 'ACCDB' );
I receive: ERROR: unable to find format "ADDCB"
HINT: See the formats list at http://www.gdal.org/ogr_formats.html.
I also tried MDB and received the same error. However, MDB is the code name given by the website but it says that it needs JDK/JRE to compile and I'm not really sure if that's another type of driver that I would need or what it is.
When I try:
CREATE SERVER metadata
FOREIGN DATA WRAPPER ogr_fdw
OPTIONS (
datasource 'H:\Databases\20170712.mdb',
format 'ODBC' );
I receive: ERROR: unable to connect to data source "H:\Databases\20170712.mdb"
SQL state: HV00D
Hint: Unable to initialize ODBC connection to DSN for DRIVER=Microsoft Access Driver (*.mdb);DBQ=H:\Databases\20170712.mdb,
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
However I thought after looking at the github help page for ogr_fdw didn't need ODBC and special drivers https://github.com/pramsey/pgsql-ogr-fdw/blob/master/FAQ.md.
A lot of this is probably due to my limited knowledge of the terminology when I'm reading through a lot of this stuff. Also my Access database is an .accdb file but since that wasn't working I tried around with mdb and ODBC as the "format" too. If anyone has any suggestions I would greatly appreciate it.
Thanks!

Unable to restore cloud sql backup

I followed this link to restore my backup
https://cloud.google.com/sql/docs/mysql/backup-recovery/restoring
and i've tried restoring on multiple instances too
but in every instance's this error comes up in logs
Couldn't repair table: mysql.general_log
Failed to write to mysql.general_log: Incorrect key file for table 'general_log'; try to repair it
First, address the error. Your general query log is enabled, but the install default is disabled. If you do not need the table enabled, then once everything is working, disable it. I would suggest take a fresh backup and then:
A. Repair the table using the mysqlcheck -r YourDB general_log command. (If this is an ISAM table use myisamchk instead.)
B. If that does not repair the table, first try mysqlcheck -r YourDB to repair the whole database (sometimes more than just the table needs to be repaired.)
C. If the restore still doesn't work than there are a couple of possibilities: the database may be corrupted or the backup file is corrupted. You don't mention any other errors, so I do not suspect the whole database is corrupted.
D. To check on the corrupted file, you can create a fresh database instance and try your restore there. If that does not work you can try restoring a data table to confirm if the backup file is usable.
Be prepared for the possibility your backup file is corrupt.

Can't rename postgres database that has mixed case name

The database's name is Parkes and I want to rename it Parkes1
I have tried
myconn.Execute "ALTER DATABASE ""Parkes"" RENAME TO ""Parkes1"";"
and pretty much every variety I can think of but they all return the message,
error near '"Parkes"'
meanwhile if I try
myconn.Execute "ALTER DATABASE Parkes RENAME TO Parkes1;"
the message says
unable to find database parkes
I can't see what I am doing wrong, it's postresql 9.4 that I am using and I am using ADO via the postgresql odbc library from vb6 to try to do the rename.
I can rename it fine using pgadmin3 but I need to be able to do it programmatically.

Catalyst - Creating DB dump - Getting "No tables found, did you forget to specify db_schema?" on MS SQL Server connection

I'm trying to create a Catalyst project connecting to an existing MS SQL Server database. I got the correct connection string and it's authenticating, but it's not finding any tables. Anyone have an idea of what I might be missing?
I substituted the real ip address, database name, username, and password but you get the idea.
This is the command I run:
script\qa_utility_create.pl model DB DBIC::Schema QA_Utility::Schema create=static "db_schema=DatabaseName" "dbi:ODBC:Driver={sql server};Server=1.1.1.1,1433;Database=DatabaseName" username password
When I run this, I get the below error:
exists "C:\strawberry\perl\site\bin\QA_Utility\lib\QA_Utility\Model"
exists "C:\strawberry\perl\site\bin\QA_Utility\t"
Dumping manual schema for QA_Utility::Schema to directory C:\strawberry\perl\site\bin\QA_Utility\lib ...
Schema dump completed.
WARNING: No tables found, did you forget to specify db_schema?
exists "C:\strawberry\perl\site\bin\QA_Utility\lib\QA_Utility\Model\DB.pm"
Check your db_schema as the error suggests. The default is usually "dbo".
So I had similar issues connecting with a mySQL database which drove me crazy for about 4 hours (I'm a newbie to Catalyst).
the create script was executing ok, but failed to pick up any tables giving the "WARNING No tables found...."
The tables were present however in the database.
Prior to this, I had been getting errors when the script tried to connect to the database, and after playing with the arguments for a while, the connection errors cleared and I assumed all was good at this point (wrong !!!!).
The suggested solution to specify the db_schema was misleading at this point, as the problem was more an issue with the connection failing to return any valid data. So I think what was happening was it was finding the database, connecting ok, but not returning any data, thus no tables....
After about 4 hours of playing with the arguments for the connection one combination just magically worked.
So here is the successful command line....
script/testcatalyst_create.pl model DB DBIC::Schema testcatalyst::Schema::perl_test create=static dbi:mysql:perl_test:user=root
The parameter which was causing the error was the last parameter which specifies the connection parameters dbi:mysql...
previously I had tried...
script/testcatalyst_create.pl model DB DBIC::Schema testcatalyst::Schema::perl_test create=dynamic dbi:mysql:perl_test,username=root
and many other formats from various online searches. The ":user=root" turned out to be the correct format.
Hope this helps someone else !!!!!!!