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 :-)
Related
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.
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.
I installed postgresql on windows and while the installation it asks to make a user for the account.This made a new windows user in my computer called postgres, I have created a password for it as well.
Now I want to run psql on windows command line, it asks for a password (without mentioning the user) and always gives me back the error: psql: FATAL: password authentication failed for user "Ash". Even though I have put my accounts password many times.
using pgadmin I changed the user "postgres" to "Ash" but I have yet to remake the password. I followed the steps here: I forgot the password I entered during postgres installation (I rather types host all 127.0.0.1/32 trust because I am on windows), but when running psql again so that I can change the password I get the error: psql FATAL:could not load pg_hba.conf. All together.
Why can it not load? All I did was add an extra authentication option.
Also, is the windows user separated from a postresql user or are they the same(depend on each other)?
Edit:
As you can see, it did not give me the option to choose if Aisha should be a superuser or not. or the other options for that matter.
I also used pgadmin||| to create a new user but the same error pops up:
The user does not exist so why does it do this?
The user on your machine has nothing to do with the user on PostgreSQL. The installer just creates an account and a PostgreSQL role with the same name and password (which in my mind is a bad idea), but they're not related in any way. The Windows user is used to run the server, the PostgreSQL role is used inside the database.
So you should first access the server with the user postgres and then create a user for yourself. Don't change the username inside the server, or the server's running user! Just create a new username and grant it the permissions you need.
You can use psql -U postgres to connect to the server and it'll ask for the password.
Check the permissions for pg_hba.conf, the postgres user must have permissions for it. If you only edited it as an admin, it should be ok, but if you took permissions or anything else, it may mess it up.
createuser is a command-line utility. Use CREATE USER username WITH PASSWORD 'fred'; or similar at the SQL level in psql. Note the semicolon.
What you're doing in your screenshot is starting to write an SQL command beginning with createuser, but never sending it to the server to run because there's no semicolon terminator. So you never get the error that would tell you it doesn't make sense to do that.
I had exactly the same problem and this line solved it;
createuser --createdb -U postgres --login -P 'your_new_user'
#sami-kuhmonen was right, but his approach of solving the problem did not work for me.
This can also happen if the encryption for stored passwords does not match the encryption for connections as defined in postgresql.conf ang pg_hba.conf
For example, if postgresql.conf has:
password_encryption = md5
but pg_hba.conf has:
host all all 10.0.0.110/24 scram-sha-256
Then all connections on the 10.0.0.110 interface will have the 'FATAL: password authentication failed error'.
Remember that if you change either of these files you will need to restart postgresql and if you change the password encryption in postgresql.conf you will need to change the passwords for all of the users.
Hope this helps some others with this problems.
I was having the same error. I get to solve it by locating the "pg_hba.conf" file. You can use this navigation:
C:\Program Files\PostgreSQL\14\data\pg_hba.conf
Then inside the file, changed all the methods "scram-sha-256" to trust and problem was solved.
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.
I am having a hard time running my Magento site website locally using xampp. I have downloaded everything in the public_html to the htdocs folder. It is giving me a n error when i load
SQLSTATE[HY000] [1045] Access denied for user 'mySite_magstore'#'localhost' (using password: YES)
I loaded up the phpmyadmin panel to check the password but it is not loading the one from my website but the new one i have locally. I'm sure I am missing a step here as well.
All the information I have found online is regarding setting up a new site on xampp but could not find anything about using an existing one. Any help or links would help.
Thanks!
If you want to create a test environment in your machine, try the following steps:
Export your live DB
Import it in your local machine
Go in to the core_config_data table and change the 'value' of:
web/unsecure/base_url
And:
web/secure/base_url
To:
http://127.0.0.1/
Go in to:
app/etc/local.xml
And change the username and password to the correct ones
Edit:
Thanks to Cooper Maruyana for bringining this up:
If the previous step doesn't help delete everything in the 'var' folder.
Check your app\etc\local.xml for below line
<password><![CDATA[]]></password>
I am sure you have set some password for production server, but on your local you don't have any password for your root user. So you need to remove that password and also set you base URL in core_config table.
There are two possible options: one is to copy your database from your server to your localhost as pzirkind has illustrated in his answer.
The second option in case you want to use exactly the same database, i.e. you WANT to use your live database:
You need to adjust your app/etc/local.xml file to point to the database server IP address. Currently there should be "localhost" in there. Remove that and put the database server IP address. If you have setup the user on the database to allow remote access (% for scope in phpmyadmin), then this would work, too.
However, I would not recommend this option. I only use it sometimes to share a database between development and staging areas, but never for live sites.
Therefore, I would highly recommend pzirkind's approach!