Where to find the PostgreSQL db file in Cloud9? - postgresql

I recently switched from SQLite to PostgreSQL and am using Cloud9 IDE (Rails). With SQLite there was a file db/development.sqlite that I could open to examine the db contents. Where can I find a similar file now I've switched to PostgreSQL?

You should be able to use the following:
sudo sudo -u postgres psql
to access your PostgreSQL server. Here's some documentation from Cloud9 regarding PostgreSQL.

Related

ERM from PostgreSQL via psql (SQL Shell)

I need to understand the relations between tables in a PostgreSQL database. I will not have the ability to download pgAdmin4 like I am used to working in. So after looking around I found pg_dump.exe built into PostgreSQL. I thought I could just do something like this in the SQL Shell (psql) to get a dump of the database and then have the ability to upload it into another system:
database=# pg_dump database > path/to/save/file.sql;
Based on the docs >> https://www.postgresql.org/docs/9.3/app-pgdump.html
But when I run that I get an error:
ERROR: syntax error at or near "pg_dump"
LINE 1: pg_dump database > path/to/save/file.sql;
^
I saw on this stack overflow question was similar to my issue with the pg_dump error. In the solutions, Adrian says that pg_dump does not work within psql. When I run the code that Adrian suggested, I also get an error.
Any thoughts on how I can use psql to get the information that I need of this database?
Note: I am accessing a Linux VM on a Windows machine.

Syntax to make pg_dump target an older version of pg_restore

I have a postgres 12 database in use on heroku with postgres 11 installed on my macOS workstation. When I try to restore the file provided to me by Heroku, I get
$ pg_restore --verbose --no-owner -h localhost -d myapp_development latest-heroku.dump
pg_restore: [archiver] unsupported version (1.14) in file header
According to Heroku's documentation, they make it sound like the only option is that if a Heroku user wants to access their data locally, they must be running postgres 12? That seems silly.
Digging into the Postgres docs on this topic, they say:
pg_dump can also dump from PostgreSQL servers older than its own version. (Currently, servers back to version 8.0 are supported.)
Which certainly sounds like it should be possible to specify a target version of pg_restore to be used by pg_dump? But nowhere on the internet does there seem to be an example of this in action. Including the postgres docs themselves, which offer no clues about the syntax that would be used to target the "dump versions back to version 8.0".
Has anyone ever managed to use the pg_restore installed with postgres 11 to import a dump from the pg_dump installed with postgres 12?
The best answer to this that I figured out was to upgrade via brew upgrade libpq. This upgrades psql, pg_dump and pg_restore to the latest version (to link them I had to use brew link --force libpq). Once that upgrade was in place, I was able to dump from the postgres 12 databases on heroku, and import into my postgres 11 database locally. I thought I might need to dump to raw SQL for that to work, but thankfully the pg-12 based pg_restore was able to import into my postgres 11 database without issue.
pg_restore will refuse to handle a dump with a later version than itself - basically, if it encounters a file "from the future", it cannot know how to handle it.
So if you dump a database with pg_dump from v12, pg_restore from v11 cannot handle it.
The solution, as you have found out, is to upgrade the v11 installation.

Dump Contents of RDS Postgres Query

Short Version of this Question:
I'd like to dump the contents of a Postgres query from a db instance hosted in RDS inside of a shell script.
Complete Version:
Right now I'm writing a shell script that I would like to dump the contents of a query into a .dump file from a source database, and run the dump file on a destination database instance. Both db instances are hosted in RDS.
MySQL allows you to do this using the mysqldump tool, but the recommended answer to this problem in Postgres seems to be to use the COPY command. However, the COPY command isn't available in RDS instances. The recommended solution in this case seems to be to use the '\copy' command, which does the same thing locally using the psql tool. However, it doesn't seem like this is a support option inside of a shell script.
What's the best way to accomplish this?
Thank you!
I am not familiar with shell, but I have used batch file in Windows to dump output of query to a file and to import the file on another instance.
Here is what I used to export from postgres RDS to file on Windows.
SET PGPASSWORD=your_password
cd "C:\Program Files (x86)\pgAdmin 4\v3\runtime"
psql -h your_host -U your_username -d your_databasename -c "\copy (your_query) TO
path\file_name.sql"
All above commands are in one batch file.

Moving a firebird 2.5 database

So currently I have firebird 2.5 installed and running on Windows, working fine but performance is a bit slow.
I have installed 2.5 on Ubuntu, and I can connect to the current database with ISQL easily:
connect "192.168.155.112:C:\database\database.FDB" user 'SYSDBA' password 'adminpassword';
So I stopped the firebird services on the Windows server, copied the file to the Ubuntu server, and in isql tried to run:
SQL> connect "localhost:/var/lib/firebird/2.5/data/database.FDB" user 'SYSDBA' password 'adminpassword';
Statement failed, SQLSTATE = m
file /var/lib/firebird/2.5/data/database.FDB is not a valid database
Note I have so far tried:
~$ sudo adduser `id -un` firebird
[sudo] password for luke:
The user `luke' is already a member of `firebird'.
As well as
# chown firebird /var/lib/firebird/2.5/data/database.fdb
With no luck, if anyone has any idea as to why I might be getting this error, I would be very grateful :)
I am not sure if Super or Classic was used on Windows, however I have tried using both on Ubuntu with the same error message. Windows server version 2.5.6, same version on Linux
You need to backup the database using gbak, and then restore it using gbak.
To backup:
gbak -backup employee D:\backups\employee.fbk
To restore:
gbak -c /backups/employee.fbk employee
Where employee is either the path or the alias of the database.
See also the gbak manual for more information.

How openshift - postgresql load data from local file?

I created app on openshift and added a cartridge postgresql.
There is no manage application like pgadmin supported by openshift.
I manage the DB by PuTTY under windows.
But how I can import the local data to the DB on openshift.
Thank you in advance!
First take backup of your database using below command.
pg_dump dbname > outfile
Then
add the postgresql database like so
rhc-ctl-app –a postgresApp –e add-postgresql-8.4
then access the remote psql and you can restore using this command pg_restore