Console access to Dokku's PostgreSQL plugin? - postgresql

Is there a way to get console access to Dokku's PostgreSQL plugin? On Heroku I'd do heroku pg:psql. Is this possible in a Dokku environment and if so how?

There is in fact a way to do this directly with the dokku-pg-plugin.
The command postgresql:restore <db> < dump_file.sql connects to the specified database and restores it with the provided dump file. If you simply omit the dump file part (< dump_file.sql), a psql console session opens.
Since postgresql:restore <db> is semantically not the best way to open a console session, I have opened a pull request to add the command postgresql:console <db>.
So, until my PR is merged, the options for opening a psql console for a database are either:
doing it manually with psql -h 172.17.42.1 -p <port> -U root db with the <port> and password taken from the output of dokku postgresql:info <db>,
using the semantically incorrect command dokku postgresql:restore <db>, or
use my forked and patched version of the plugin which adds the command postgresql:console <db>.
Edit:
The owner of the dokku-pg-plugin has merged my pull request. If you're using this plugin and are looking for a way to access your PostgreSQL console with it, you might want to update it to the latest version. Once you have done that, you can use the command postgresql:console <db> to open a psql session to the specified database.

This worked for me for my Rails app that I'm running on Dokku:
dokku run <app-name> rails db
That brought up the console for the PostgreSQL container I created (via dokku postgresql:create <db>). I couldn't figure out another way to get at the PostgreSQL instance in that container, short of attempting to directly connect to the DB, with the connection info/credentials listed when you do this:
dokku postgresql:info <db>
I haven't tried that, though I suspect it would work.

Related

creating a postgresql database back end for a new Label Studio project

I am creating a local Label Studio server to host images to annotate in our office. I would like the database back end to be postgresql and not sqlite and be located in a particular directory, not the default and not the same as the 'data-dir'. I have got a test server working across the network with various machines annotating images on the server, but the backend was sqlite for this test.
Everything I've tried to get a postgresql backend db has failed for various reasons. Some commands result in a sqlite db (occasionally with the name 'postgresql') located in my required directory; others create postgres/pyscopg2 errors but I think they're up a garden path.
The host machine is running Ubuntu 20.04 LTS. And serves another postgresql db over the network using other APIs. Postgresql version running is 12.9.
I have created a conda environment and pip installed Label Studio as the documentation suggested.
Here's what I've tried:
Start the conda environment. Follow instructions to assign environment variables from https://labelstud.io/guide/storedata.html#PostgreSQL-database which at time of writing is:
DJANGO_DB=default
POSTGRE_NAME=postgres
POSTGRE_USER=postgres
POSTGRE_PASSWORD=
POSTGRE_PORT=5432
POSTGRE_HOST=db
Then a few variations on the start command (I didn't include the backslashes, just put here for readability/comparability):
label-studio start --init \
-db postgresql \
--database /path/to/label-studio/databases/newdb \
--data-dir /path/to/label-studio/media_dirs/test_proj
result: db is where expected, but:
file newdb
gives "newdb: SQLite 3.x database, last written using SQLite version 3038002"
label-studio start --init \
--database /path/to/label-studio/databases/newdb \
-db postgresql \
--data-dir /path/to/label-studio/media_dirs/test_proj
result: a db at specified path named 'postgresql' and still an sqlite db. This seems to mirror the mistake mentioned at: https://github.com/heartexlabs/label-studio/issues/1660
I have also tried the above two commands with the '--init' argument omitted with same results.
Then I tried adding something on the front of the command suggested at the same link above:
DJANGO_DB=default label-studio start \
--database /path/to/label-studio/databases/newdb \
--data-dir /path/to/label-studio/media_dirs/test_proj
result: psycopg2.OperationalError: FATAL: password authentication failed for user "postgres"
FATAL: password authentication failed for user "postgres"
DJANGO_DB=default POSTGRE_PASSWORD= label-studio start \
--database /path/to/label-studio/databases/newdb \
--data-dir /path/to/label-studio/media_dirs/test_proj
result: psycopg2.OperationalError: fe_sendauth: no password supplied
Any help and resolution would be highly appreciated.
Also, I can't tag this with 'label-studio' because I'm not quite at the required reputation to create a new tag, so if anyone who can feels like doing so, pleaseandthankyou!
Your last option was closer than all the others. Have you tried to run LS using this:
DJANGO_DB=default POSTGRE_NAME=<postgres_name> POSTGRE_USER=<postgres_user> POSTGRE_PASSWORD=<password> POSTGRE_PORT=<db_port> POSTGRE_HOST=<db_host> label-studio
Sure, you have to run postgres service by yourself, configure it properly, create the DB <postgres_name>, the user <postgres_user> and set the password <password>, grant access rights to this user. Also don't forget to specify <db_host> (localhost?), <db_port> (5432?)

How to reset the DB on each deployment on heroku?

So currently I'm working on a project on Heroku with Drupal and my issue is that I want to reset the database each time I deploy to master, yes I know it not ideal but its a development env because I'm working Drupal plugin and it would be nice if changes happened it could just reset to a state.
But when I try to connect using psql and some variables I just get password authentication failed for user even tho I know its the right password because I got it from Heroku itself.
Currently, I have tried using the console to try to make in connection soi could run a DROP TABLE command for me to afterword import an SQL file with the basic setup using pg_dump, and put it into a .sh script and run it with and release: in a procfile
Until now I have this as a release.sh file where I only tried in the console on heroku
PGHOST=HOST PGPORT=5432 \
PGDATABASE=DB \
PGUSER=USER PGPASSWORD=SOMEPASS \
psql
Try below command to reset DB
heroku pg:reset DATABASE_URL

Clone Mongo DB from Server to localhost in Meteor App [Environment Variable]

I have a Meteor App running on Modulus.net server. The App is using by many people, So I want to use the same Database Locally. I'm using Ubuntu 12.
I read other SO Posts, but none of them found useful.
I tried this code
$ export MONGO_URL=mongodb://user:pass#mongo.onmodulus.net/dbId?autoReconnect=true&connectTimeoutMS=60000
$ meteor run
It throws an Error
Unexpected mongo exit code 45. Restarting.
Can't start mongod
MongoDB cannot open or obtain a lock on a file
I have also tried sudo mrt as I have installed meteorite, now the app is running but the database not changed.
I'm a newbie to Terminal, Is there any way to do that?
Did you replace user:pass and dbId to your username, password, and dbID?
You can use mongo mongodb://user:pass#mongo.onmodulus.net/dbId to check whether you can access it or not first.
Update
Sorry for the misleading answer, mongo shell has a bug to log in while you enter the url like so. You can see here
Your code runs successfully on my computer. You can try to delete .meteor/local and then execute meteor run again.
If you want to use sudo to execute it, add the argument -E so that the environment variables will not be reset:
sudo -E meteor run

Push local postgresql database to heroku: The local psql command could not be located

I'm trying to push a local postgresql database to my heroku project. Unfortunately, it doesn't work.
Postgresql works perfectly on my computer and the psql command works as well (Path is set correctly to the bin folder)!
But when I try to push my databse with
heroku pg:push mylocaldb HEROKU_POSTGRESQL_MAGENTA --app sushi
(with my db name as mylocaldb and my real app name), it doesn't work at all.
Problem: The local psql command could not be located
Why? As said before, psql works fine. Even a reinstall of postgresql doesn't help.
The pull statement (see: doesn't work either because postgres always wants to authenticate as my windows user (I don't know how to change the user name when using the heroku pg:pull command, this didn't help: https://devcenter.heroku.com/articles/heroku-postgresql#pg-push-and-pg-pull)
Thanks for your help!
Have you tried calling the psql command with its full path?
For example: /opt/PostgreSQL/9.1/bin/psql
Or if that doesn't help, you can try this

Heroku postgresql db sharing between 2 apps error

I can't manage to share two PostgreSQL heroku dbases between two heroku apps.
Doesn't work
What I've tried so far (I'm using the Heroku CLI):
$ heroku config:set DATABASE_URL=`heroku config:get DATABASE_URL -a my-heroku-app-original`
Setting config vars and restarting my-heroku-app... done, v20
DATABASE_URL: postgres://...correct url...
$ heroku config
=== msite-poniai Config Vars
DATABASE_URL: postgres://...correct url...
When I try to access psql, depending on whether I've added a new db or not, I get these two answer (I both cases heroku doesn't see the DATABASE_URL I've just provided.
$ heroku pg:psql
! Your app has no databases.
$ heroku pg:psql
! Unknown database. Valid options are: HEROKU_POSTGRESQL_NEWLYADDED_URL
Works
If I provide psql with the exact location of the db (in this case the original app that has the db as an add-on) it does manage to connect.
$ heroku pg:psql HEROKU_POSTGRESQL_ORIGINAL_URL --app my-heroku-app-original
psql (9.1.9)
I've read
I've closely followed advice given in Share database between 2 apps in Heroku and heroku-postgresql#create-new-db.
Simply copying a config var from one app to another does not attach the referenced database to the app. Were the host or password to change on the first, your second app would be broken. There is a highly alpha plugin you can try https://github.com/heroku/heroku-attachable-resources but it does some weird things like no longer give default names to databases, and overwrites DATABASE_URL if you don't pass in --config and sometimes doesn't let you remove databases.