dokku-alt postgres superuser - ruby-on-rails

I am trying to use dokku-alt (https://github.com/dokku-alt/dokku-alt) to provision a VPS for a Rails App (Ruby 2.1.3, Rails 4.1.2), but my app uses a Postgres extension (pg_trgm).
Unfortunately dokku-alt doesn't currently support the admin_console command, as opposed to here: https://github.com/jeffutter/dokku-postgresql-plugin
Does anyone know of a way to get into the postgres console using the root or postgres user given that Docker is being used?

Yeah you can do it like so:
docker ps
That should give you a list of containers and their ID's, find the one that is running your postgres instance (could be one for all apps, might be one for each other app)
docker run <container_name> psql

If you're using even close the latest version of dokku-alt, there is a admin console command.
I recently ran into a problem where I had to grant super user access to one of our apps.
What I did was
dokku postgresql:console:admin <<EOF
ALTER USER dbusername WITH SUPERUSER;
EOF
Running dokku postgresql:console:admin should give you direct access into the main psql console.

Related

Rails app can't find connect to postgres after working on a different app for a while

So I just need to direction on understanding a postgres installation better, because clearly I only know enough to be dangerous.
I had an app that was my project with a postgres DB installed via homebrew
Then I started collaborating on a project with other people
There was some difficulty getting my existing prostgres install to work with the new project so I installed the postgres app with the gui interface to start stop the db.
That new project is finished and I wanted to get back to work on my other project
When I started the first app up, it couldn't find a db. I tried drop the db, and recreating it, but when I run the migrations it says the tables already exist.
What can I do to get around this?
A good approach would be using Docker so everyone have the same environment. This would mean even you, across your machines or your working colleagues or collaborators would have the same environment. You could have many containers running (watching exposing different ports for Postgres, i.e: 5433...) and when a project finishes just get rid of the container.
This approach saves you the overhead of having to maintain multiple databases locally or depending on a running Postgres process (which I sometimes forget to start).
If you need to solve this locally, try starting your postgres service, connecting to your localhost instance and running:
> psql
psql (9.6.2)
Type "help" for help.
> \l
and you should see all of your databases and debug them. Perhaps deleting and creating the conflicting database (if you don't need your local data) could help.

Rails server on AWS hosting

I have hosted a rails application on AWS. Every time I want to access my website, I have to go through some steps which are quite repetitive.
1. ssh -i <<a>my-keypair-pem> ec2-user#<<a>AWS-IPv4-public-IP>
2. rails s -p <<a>port> -b 0.0.0.0
After some time, I also get this error
'packet_write_wait: Connection to <AWS-IPv4-public-IP> port 22: Broken pipe'
I did some research and can't seem to find a way to keep my application running 24/7 without having to do these steps before accessing every time.
My AWS instance is on 24/7, so the website should run 24/7 as well.
Would assign an elastic IP to my instance help?
Appreciate any guidance.
EDIT: I followed this tutorial initially https://www.youtube.com/watch?v=jFBbcleSPoY and that is where I found the steps mentioned above.
There are many ways to run the rails server as daemon. If you google for "rails server as daemon", you will see many links. Have not added any links as many of good links are by hosting service providers.
If you still want to run the rails server through the shell for some reason, tmux is the way to go. The following excerpt is shamelessly copied from Tmux Wiki.
tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal.
You can open a tmux terminal and start rails server. You can detach from the tmux and quit your ssh session. Whenever you wish, you can ssh back to your server and re-attach to the tmux session. You rails server will still be running as you left it. This is great way to run development server in foreground for debugging.
Resolved the issue with https://mosh.org/, for anyone who stumbles on this post in the future.
Download and install mosh (mobile shell)
Run the modified version of the command mentioned in my original question
mosh -ssh="ssh -i <your-keypair.pem>" ec2-user#<AWS-Instance-IP>
This resolved my packet_write_wait issues and I don't have to keep restarting the rails server.

How to connect Sequel Pro with Laradock

I can not connect my Laradock docker with Sequel Pro.
In my .env file
### MYSQL
MYSQL_VERSION=8.0
MYSQL_DATABASE=default, athsurvey
MYSQL_USER=homestead
MYSQL_PASSWORD=secret
MYSQL_PORT=3306
MYSQL_ROOT_PASSWORD=root
MYSQL_ENTRYPOINT_INITDB=./mysql/docker-entrypoint-initdb.d
And in my Sequel Pro interface, I put :
host: 127.0.0.1
user: homestead
pass: secret
But it does not work. Do you have an idea of how to make my connection successful? It should be simple ...
thank you very much!
There's a known issue currently with Sequel Pro connecting to MySQL 8 that's still unfixed yet, reference: https://github.com/sequelpro/sequelpro/issues/2699
Also TablePlus has similar issue (despite it's said to be working), reference: https://twitter.com/Omranic/status/1011385798820859904
Currently I'd advice using either command line, or Jetbrain's DataGrip which works fine with MySQL 8, or as a final option if you don't mind which version of MySQL and you're developing locally, you can downgrade to v5.7 until these GUI tools are being fixed and be ready. Hope this helps..
Have you checked the MYSQL related environment variables in laradock's .env file?
Homestead/root combo is not familiar as default credentials for me.
Try root/root for user/pass combo and default for database.
Using MYSQL_USER=homestead and MYSQL_PASSWORD=secret are not the default options. If you have edited laradock/.env file after the container was already started at least once, you should rebuild the MySQL container so changes are applied.
docker-compose stop mysql
docker-compose build --no-cache mysql
docker-compose up -d mysql

how to export postgres database from aws rds

I have a Rails 4 app deployed to Elastic Beanstalk using Postgresql. My question is: what is the best way (or a good way) to export the database?
I tried to use pg_dump from the ec2 instance which is part of the RDS security group but the ec2 instance has a different postgres version (9.2.9). I was also unable to make this happen using the AWS console.
Any general advice on how best to proceed would be much appreciated.
pg_dump is the way to go, but sounds like you'll just need to ensure that the host running pg_dump is running with the same version as the RDS server instance.

Mongodb is not working upon restart in rails app

I had to force a restart of my linux computer and upon turning back on, nothing related to my Mongodb installation is functioning properly.
My rails app, using Mongoid, is giving this error:
Could not connect to any secondary or primary nodes for replica set <Moped::Cluster nodes=[<Moped::Node resolved_address="127.0.0.1:27017">]>
on attempting to load a page and a similar error in the rails console.
Everything was running smoothly before and I am not sure how to right this ship.
I generally get this error when the mongo daemon is not running. Try running something like this:
sudo mongod --fork --logpath /var/log/mongodb.log --logappend
The method used to automatically start on system boot will vary depending on your OS. What flavor of Linux do you run?
i don't know it is right or wrong way but it always work for me
rm /data/db/mongod.lock
mongod --dbpath /data/db --repair
mongod --dbpath /data/db

Resources