Connect to Heroku Postgres through external application - heroku

I have a Heroku Ruby app, and I want to access the DB through Navicat, or pgAdmin, or similar. However, the thing that Heroku gives me as a DB URL doesn't seem to be a valid URL.
Heroku tells me to use: heroku config:get DATABASE_URL -a your-app However, that gives me something of the form
postgres://HUGE:STRINGOF#GIBERISH.compute-1.amazonaws.com:5432/MORECHARACTERS
which doesn't look like a valid URL to me, and both Navicat and pgAdmin fail to connect.
How can I use this value to connect to my database?

That "huge string of gibberish" is a completely valid URL.
postgres is the scheme, just like https is a scheme.
What you have marked as HUGE is your username and what you have marked as STRINGOF is your password. Together, they make up the userinfo subcomponent.
GIBERISH just is part of the domain, 5432 is the port, and MORECHARACTERS is the name of the database.

Related

Connect to a remote PostgreSQL database Windows

I'm new at this and I got a job where I need to connect to a PostgreSQL database, they told me to use this command:
psql -h remote_ip -p 54320 -U user -d database
I'm trying to connect with Navicat but this error occurs:
psql: FATAL: no pg_hba.conf entry for host "18.221.220.67", user "pse", database "pse", SSL off
It sounds like you are not the DBA of this database, and whoever is the DBA forgot to configure the database to let you in. You will have to have them fix it for you. Maybe you are supposed to be coming in through a VPN which will change your apparent IP address (although in that case I would think you wouldn't even be able to contact the database without the VPN; as it would be blocked at the firewall). Or perhaps you are only allowed to connect over SSL, but navicat is not trying to do that for some reason.

How to securely connect to PostgreSQL database, with Ruby?

I feel uncomfortable saving my password in a file:
require 'pg'
conn = PG::Connection.open(host: 'server.example.com', password: 'hello_everyone')
Also, is there a way to determine or ensure that the transmission is encrypted? I am just worried about the implications of running my app locally, when it must connect to a remote database (I am worried about all the data, including the authentication credentials, being sent in the clear).
Regarding the password:
I would recommend setting it in an ENV variable. Take a look at dotenv gem. Basically, you are going to be able to do something like:
require 'pg'
conn = PG::Connection.open(host: ENV['database_host'], password: ENV['database_password'])
The values that are loaded into ENV will be stored in a file (.env) which you should not commit.
Regarding data encryption
You should take a look at SSH tunneling to connect to the remote DB.

Setting Pakyow for local development with Postgres

In the blog post about connection to postgres, http://notmagic.org/2015/04/10/pakyow-sequel, how do you deal with Postgres setup and required password errors?
I've been developing in Nitrous.io but now setting up local development. So I set the DATABASE_URL as in the post but trying to run pakyow server it gives an error about: "pg::connectionbad: fe_sendauth: no password"
The only user in Postgres is 'postgres' and it has a password associated. It wouldn't let me install without creating a password.
Also, is it bad practice to not have a Postgres password for local dev? Articles about it weren't clear (and were related to Rails) and mentioned database.yml storing the password, which Pakyow doesn't seem to have.
If you follow the post, you'll want to include the password in the DATABASE_URL environment variable (in your local .env file). The url should be structured like: postgres://user:password#host/database.
It's best to always have a password for your Postgres user, be it locally or in production. You want to make it as difficult as possible for someone to see your data :-)

How does Codeigniter know where mysql server is located?

I know this is a very newbie question. So supposed we have a wamp server installed, and downloaded codeigniter. Does the codeigniter find the mysql application through the environmental variable path like it shows on the phpinfo() page? If possible, could you tell me where I can see this configuration within the codeigniter application. The database.php file doesn't seem to have mysql path.
You have to define mysql credentials within application/config/database.php, so codeigniter can connect to your database.
To connect no path is required, instead you have to provide host, username and password.
In your case:
host: localhost
username: root
password: your default root password
Read here: https://ellislab.com/codeigniter/user-guide/database/configuration.html
In general, MySQL server is to install as a Windows Service (Daemon on linux), it can be controlled from the command line, or with the graphical services utility.
PHP interacts with MySQL by connecting to it using TCP/IP. So needless, we have to provide
credentials like hostname, port(default 3306), username ,password etc in order to connect with it. More details can be found here.

Ruby -> PostgreSQL connection with pg_hba.conf set to "ident sameuser" instead of "trust"

I've tried every Google search term I can think of but everything I dig up keeps saying to set local connections to trust in pg_hba.conf (seems like a security hole if anyone locally can log in and access the DB as anyone they say they are).
In pg_hba.conf local connections are set to ident sameuser. The script should be running as that user, but I get this error:
A database error occurred:
fe_sendauth: no password supplied
The Ruby code is pretty generic:
conn_str = "DBI:pg:dbname=mydb;host=" + localhost
#connection = DBI.connect(conn_str, "myuser", '')
I can work around this by creating a ~/.pgpass file as described here,
but I'd prefer being able to let users log in and just access the DB server.
Anyone ever been able to get PostgreSQL's ident sameuser to work properly for local scripts?
I suspect this:
In pg_hba.conf local connections are set to ident sameuser. The script should be running as that user, but I get this error [...]
conn_str = "DBI:pg:dbname=mydb;host=" + localhost
#connection = DBI.connect(conn_str, "myuser", '')
Please note that a "local" connection is not the same as a connection to "localhost". As soon as you mention "localhost" in the connection URL a TCP/IP socket is created. These are managed by the host rules in `pg_hba.conf.
To use a real "local" connection Unix Domain Sockets must be used. But I don't know whether or not the Ruby DBI connector supports them.
The ident setting works for me for local system users and PostgreSQL 8.4. You may have to adjust your pg_hba.conf settings.
Check your database log files to see where the connections come from exactly and whether the system user name matches the database role name. You may have to activate log_connections in your postgresql.conf for that.
The manual really does a nice job explaining authentication methods.
If system user name and database role name don't match, you'll have to use a .pgpass file. But your passwords should still be safe. Only the system user postgres gets to read it. I quote the manual:
On Unix systems, the permissions on .pgpass must disallow any access
to world or group; achieve this by the command chmod 0600 ~/.pgpass.

Resources