Setting Up PostgreSQL for initial use on Mac OS - macos

I've installed PostgreSQL 9 on my local mac and it installed the "SQL Shell (psql).app" which I assume is the command shell for the server. I've opened it up but it asks for a Username [postgres]:. I type in postgres and then it asks for a password. I press enter and it gives the following error:
psql: fe_sendauth: no password supplied
How do I log in and more importantly how do I run commands like createdb? I tried the createdb command in my normal Terminal window but the command is not recognized.
Should I be using Homebrew or Macports? I haven't used either of these being new to the Mac OS
Thanks for your help!

I had this problem and removing the host and port parameters from database.yml fixed it for me:
development:
adapter: postgresql
encoding: unicode
database: my_db
pool: 5
host: localhost # remove this line
port: 5432 # and this one

If your postgres user doesn't have a password, set this env variable:
export PGPASSWORD=

Related

Cannot connect to the sandbox instance due to password authentication failure

Hi~~ I'm doing the official tutorial from the follwoing link.
My system is windows 10, I'm using VirtualBox 6.0 and downloaded the latest sandbox.
The following are what I did step by setp:
(1) Boot up: I cannot upload image but the information on boot up are as follow:
Hostname: gpdb-sandbox.localdomain
IP: 192.168.5.138
GPDB Admin: gpadmin
GPDB Password: pivotal
Tutorial User: gpuser
Tutorial User Password: pivotal
(2) Navigate to pg_hba.conf and add "host all all 0.0.0.0/0 md5" to the last of it
(3) Navigate to postgresql.conf and add "listen_addresses = '*'" to it
(4) Then I loged in the OS and run the following commmand
./start_all.sh
(5) Then I opened a cmd.exe from my windows and run
psql -U gpadmin -h 192.168.5.138 -p 5432 postgres
(6) The program replies with request for password, then I typed in "pivotal"
And then the program replies with an authentication failure. Can anyone help me with that so that I can start the first step of the tutorial??
Thanks a lot!
No need to type all the parameters if you are connecting to database from the sand box terminal.
just do psql and press enter you will be connected to gpadmin database.
if you changeor add any entries in pg_hba.conf please relode the configurations by running below command.
gpstop -u

Install rails with WSL and postgresql

I'm trying to setup a rails environment development on a Windows 10.
I follow the tutorial of 'go_rails' (https://gorails.com/setup/windows/10)
Most of the installation seems to worked fine (when i type rby -v or rails -v in the bash it's return the expected result).
My issue is with postresql which is used for the project i work on it.
Following the instructions of the tutorial i install Postgresql (10) directly on Windows. It's seems to work since in can login using the pgadmin on windows or by typing 'psql -p 5432 -h localhost -U postgres' in the bash.
So it's look like postgresql is working, but when i do a rake db:create in bash, i got an error : could not connect to the server: No such file or directory. Is the server running locally and accepting connections on Unix domain socket '/var/run/postgresql/.s.PGSQL.5432'
In the postgresql.conf (C:/Programms/.../Data/postgresql.conf) the listen_addresses is set to '*'.
A bit after there is a line named '#unix_socket_directoris = ''', do you thing i should set something in there?
I really need to get that project work.
Thanks for your help
The problem is likely that you've installed the Windows binary for PostgreSQL, but you're trying to connect to it from Windows Subsystem for Linux using a Unix socket, which doesn't exist.
You need to use TCP/IP to connect rather than a Unix socket. When typing psql on the command line, add the option --host=127.0.0.1 to connect via TCP/IP.
I just went through the entire Go Rails tutorial and I also had trouble at the rake db:create step. All you need to do is add host: 127.0.0.1 to your database.yml as shown below. Make sure to Start PostgreSQL before you run rake db:create.
default: &default
host: 127.0.0.1
adapter: postgresql
encoding: unicode
username: postgres
password: ENV['POSTGRESQL_PASSWORD']
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: app_development
test:
<<: *default
database: app_test
production:
<<: *default
database: app_production
username: app_username
password: <%= ENV['APP_DATABASE_PASSWORD'] %>
Add host: localhost to your default: in database.yml. Without something telling rails where to look for the host, it looks for the process in linux, which, of course, won't work, since windows processes are not exposed to the wsl layer.

Forgot Admin Password on Postgres (Windows Installation), can't reset

I have a Windows PostgreSQL installation.
According to some posts, there is no default password set for the 'postgres' user yet I can't connect using an empty password string.
I'm receiving this exception when I try to connect:
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "postgres"
The most relevant tip was this:
https://stackoverflow.com/a/25943227/1005607
Open pg_hba.conf
Change md5 -> TRUST
then restart PgAdmin.
I tried that and restarted PGAdmin but it still asks me for the password when I try to connect:
The task manager in Windows shows some PostgreSQL processes are running. I can't switch them off.
I have tried this and it failed:
pg_ctl restart
ERROR:
pg_ctl: no database directory specified and environment variable PGDATA unset
psql.exe postgres
Password: (none)
ERROR:
psql: fe_sendauth: no password supplied
How can I reset the default password for user 'postgres'?
Based on AK47's answer and some additional info I fixed it by doing the following,
1) Stop Postgres if currently running, command line below. Need to give it the 'data' dir. In my case C:\PostgreSQL\data
pg_ctl -D C:\PostgreSQL\data stop
2) Edit the file pg_hba.conf (it's also in the \data dir) as follows:
As AK40 wrote, change all MD5 references to trust , e.g.
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
3) Now run
psql -U postgres
4) In the PG Command Prompt that appears type,
ALTER USER Postgres WITH PASSWORD '<newpassword>';
5) Save this by typing wq enter to exit the PG Prompt
6) Now start Postgres
pg_ctl -D C:\PostgreSQL\data start
7) Might want to revert the MD5 -> Trust change later in the pg_hba.conf.
Update your pg_hba.conf file to allow for trusted local connections
[root#server] vim pg_hba.conf
>> local all all trust
then restart your PostgreSQL server
[user#machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root#server] service postgresql restart (Linux)
at this point you can connect to your server as postgres user using a local connection without the need to enter a password (omitting the -h parameter when calling the psql command will use a local connection - if you pass -h then this will match the line host all all 0.0.0.0/0 <method> in your pg_hba.conf file)
[root#server] psql -U postgres
You can then alter the postgres user role and set the password to whatever you like using the following command in the psql terminal
[psql] alter role postgres password <new_password>;
Once this is done you can restart your PostgreSQL server again
[user#machine] pg_ctl -D C:\PostgreSQL\data restart (Windows)
[root#server] service postgresql restart (Linux)
and at this point your password should be changed to the new password
I was having the same issue and I couldn't use Postgres in the CLI on my windows machine but I managed to trace down where the passwords were stored via
%APPDATA%\PostgreSQL\pgpass.conf
NB: You must have selected store password option when creating a server or database in the pgAdmin.
I hope this helps. Thanks.

How to run openERP as a user but using a different database username?

I run my OpenERP through this command:
ghelo#pc$ /usr/bin/python2 openerp-server -c my_config.conf
I have these as database credentials:
username: odoo
password: some_password
My my_config.conf file has these relative lines:
db_host = False
db_maxconn = 64
db_name = False
db_password = some_password
db_port = False
db_template = template1
db_user = odoo
dbfilter = .*
My pg_hba.conf file has these append, restarting the sevice postgresql at every edit:
host all ghelo all md5
local all odoo trust
However running the server raises this exemption:
FATAL: Peer authentication failed for user "odoo"
My question is, how can i run the OpenERP server?
Other Facts:
odoo has a bash account via: $ sudo useradd odoo
psql: # CREATE USER odoo WITH SUPERUSER LOGIN CREATEDB INHERIT PASSWORD 'some_password';
psql: # CREATE DATABASE odoo OWNER odoo;
Unfortunately I have these limitations:
I cannot run sudo -u odoo COMMAND or any bash command to use a different bash user.
I can only run using /usr/bin/python2.
Bash username and database username cannot be the same.
I feel silly, I have been rule of precedence-ed. The ordering of lines in pg_hba.conf matter. I solved the issue by:
Placing this line:
local all odoo trust
Just before:
# "local" is for Unix domain socket connections only
local all all peer
and then restart your postgresql service from root user using this command:
systemctl restart postgresql.service

First ruby and postgreSql application - getting could not connect to server: No such file or directory

Ruby 1.9.3 on Mac OS X Lion
Followed several posts on SO about this topic. Neither helped.
Trying to run my first rails and postgreSQL app here.
Following this:
http://guides.rubyonrails.org/getting_started.html
When I do:
"rake db:create"
I get:
could not connect to server: No such file or directory Is the server
running locally and accepting connections on Unix domain socket
"/tmp/.s.PGSQL.5432"?
Some facts:
Not sure what /tmp/ is it referring to but, if it is the one from root, then:
1)
Permissions:
drwxrwxrwx 11 root wheel 374B Jan 4 17:33 tmp
2)
Also, I see no file .s.PGSQL.5432.
3)
I've tried to force the socket location by adding to database.yml the following:
development:
adapter: postgresql
encoding: unicode
database: testblog_development
pool: 5
username: blog
password:
socket: /var/pgsql_socket # <-- this line
(it stills shows me the same error with the /tmp/ path).
4) When I do, which postgres I get:
/usr/local/bin/postgres
(I've used homebrew installation)
5) When I do: brew info postgres I get:
postgresql: stable 9.2.2 http://www.postgresql.org/ Depends on:
readline, ossp-uuid Conflicts with: postgres-xc
/usr/local/Cellar/postgresql/9.2.2 (2819 files, 39M) *
https://github.com/mxcl/homebrew/commits/master/Library/Formula/postgresql.rb
and other bunch of information.
That seems to me like the server isn't running. Do you see anything when you run ps aux | grep postgres from the command line? If all you see is something along the lines of grep postgres in the output, it's not running.
Since you installed PostgreSQL with Homebrew, try brew info postgres for information on how to start up the server if that is indeed the case.
You don't need to specify a socket. Here's a configuration that works for Postgres. You only need to change the database password.
development:
adapter: postgresql
host: localhost
pool: 5
timeout: 5000
username: postgres
password: postgres
database: testblog_development
template: template0

Resources