Installing Postgresql and PgAdmin3 on Linux - linux

I use Postgesql and PgAdmin on Windows without any problems but am struggling to get it working on Linux (I'm a Linux N00b). I have installed the 64bit version on my Fedora box following these instructions (except substituting version 9.3 for 9.2). Everything works well until I get to launching pgsql with:
sudo -u postgres psql template1
Here I get an error "Permission denied" as is attempts to change to my home directory.
I can change the password for 'postgres' as per the instructions and I presume this is just so I can use 'md5' rather than 'trust' in pg_hba.conf (if not, then I don't understand why I need this step).
When I fire up PgAdmin3, initially I have no connections. Attempting to connect to the server gives me an authentication error for user 'postgres'. I have tried resetting pg_hba.conf to 'trust' but that doesn't work either.
I would appreciate an explanation of the 'postgres' user in Linux as it appears to be a separate actual user on the Linux system (unlike Windows where it is just a 'disembodied' user relevant only to Postgress). Secondly, help in getting PgAdmin speaking to Postgresql would be gratefully received.

psql -U postgres template1
It will prompt for password if you set md5 in pg_hba.conf

After much digging about I found that most of the documentation is incomplete. I needed a combination of connecting via Cefull Lo's solution (+1) and NOT (as in most of the documentation):
sudo -U postgres psql
Then to change the password I need a more explicit SQL command as follows
template1=# ALTER USER postgres with encrypted password ‘yourpassword’;
I presume that I need to explicitly state 'with encrypted password' because I am using md5, though again, 90% of the documentation fails to point this out and advises a basic change of password together with md5. Maybe this is specific to Fedora, who knows, but now I can connect via PgAdmin3.

Related

postgreSQL password authentication failed for user

I'm taking a full WebDev course and got really hard stuck on this matter. I've installed postgreSQL 14.2 for Windows 10 and the instructor said that pgAdmin4 would come together, which it didn't, so then i installed pgAdmin4 individually. I've setted everything up and created a testing database, which is called 'test', and also a table, everything through Windows Powershell command lines, following the course instructions. Now, when i try to access this database through PowerShell command psql 'test' and type the requested password for the OS user i get a Fatal Error, which follows:
PS C:\Users\theu_\desktop> psql 'test'
Password for user theu_:
psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "theu_"
I've tried my OS username password and the postgreSQL password, none of them works. What am i missing or did wrong?
Thanks in advance
Try accessing postgres by using psql -U postgres in cmd, postgres being the name of the superuser for postgres itself (if you did a basic install) - while windows is probably trying to access postgres with your windows name.
You should also be able to use SQL Shell to access your database without denoting a user.

Postgresqll 10: Postgres User /sbin/nologin preventing initdb setup

I'm attempting to install postgresql 10 for the first time and need to run the initdb setup. Unfortunately, this fails and returns an error from the nologin shell.
server# /usr/pgsql-10/bin/postgresql-10-setup initdb
Initializing database ...
failed, see /var/lib/pgsql/10/initdb.log
server# cat /var/lib/pgsql/10/initdb.log
This account is currently not available.
I strace'd the command and verified the su commands are probably what's causing this and it seems the default setting for the postgres user is /sbin/nologin. In various examples I've seen, there is no mention of this being a possible issue. How would this work on any other system by default? I feel that temporarily modifying the login shell would work but I want to understand this issue better more specifically from the application's end.
centos 7.8
selinux mode: permissive
postgresql 10

Accidentally removed super user privilege from user: postgres on postgres 10. How to get it back without re installing?

I accidentally removed the super user privilege from user: postgres. I don't know how to get another super user. I stopped the postgres service and tried logging in with single-user mode:
/usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
I get this error:
"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise. See the documentation for
more information on how to properly start the server.
In Linux, how can I start Postgres in single-user mode so I can fix the super user privilege?
Edit: I used this link for reference, but I'm getting the error mentioned above.
Accidently removed postgres default superuser privileges - can I get it back?
I combined solutions from these three links:
Accidently removed postgres default superuser privileges - can I get it back?
Restoring the superuser account on the postgres server
“root” execution of the PostgreSQL server is not permitted
After stopping the postgresql service, I ran this command:
sudo -u postgres /usr/pgsql-10/bin/postgres --single -D /var/lib/pgsql/10/data
/usr/pgsql-10/bin/postgres is the location of my postgres binary
/var/lib/pgsql/10/data is the location of my postgresql conf
This allowed me to access single user mode, where I just typed this command:
ALTER USER postgres SUPERUSER;
So if anyone is experiencing the same scenario as me, please give the posted command a try.
just adding this for postgresql 12 (Ubuntu) and possibly up
sudo -su postgres /usr/lib/postgresql/12/bin/postgres --single -D /etc/postgresql/12/main

Set password to meteor's mongo database

I have deployed a meteor project in a stage server and 2 days ago I found out mongodb had no password. I was able to connect to mongodb with robomongo by only providing the IP(no username, no password).
I want to set a password to protect it. I have been following this documentation but I get "mongo/mongod not a command" when writing these commands in application's root directory or after "meteor mongo" command.
What am I missing here, how can I protect mongodb with a password?
Thanks
I don't think you can, when you are running Meteors built-in MongoDB server.
The reason for this is that if you put a password on that database, Meteor will not be able to connect to it.
And to specify a password in the MongoDB connection you need to set the MONGO_URL environment variable.
And when you do that Meteor will think you are running an external MongoDB installation and it will not even start the built-in MongoDB server.
So it's kind of catch-22.
To set a password you need to have a separate MongoDB installed on your server, set a password on that one, and then tell Meteor to use it using a MONGO_URL environment variable in the format:
mongodb://username:password#127.0.0.1:27017/meteor
See https://docs.meteor.com/api/collections.html#mongo_url
Writing this as an answer because it is impossible to format text in a comment, it makes it very hard to read.
I assume you are running on an Amazon linux server, then.
If you really read the install instructions you linked to, you will see that it is not a ton of commands at all.
Install 1: Create the /etc/yum.repos.d/mongodb-org-3.2.repo file with the content given.
Install 2: sudo yum install -y mongodb-org
Run: sudo service mongod start
Done! MongoDB is now running and listening to port 27017.
You can now add a password, and set MONGO_URL as above.

PostgreSQL without password prompt : .pgpass ignored

I'm trying to enable root (Ubuntu 8.04) to use psql command without password prompt (for scripting purpose). Everything worked fine with PostgreSQL 8.3, but I migrate to PostgreSQL 8.4 and the login without password doesn't work anymore.
I've a correct .pgpass file (the same used for 8.3), the right of /root/.pgpass are 0600 but calling psql keep asking for a password.
NB : the PGPASSFILE variable is empty, so I assume that the .pgpass file is supposed to be used.
Any brilliant idea?
Try to check if this works:
*:*:*:postgres:password_for_postgres_user
And then try:
VERBOSITY=verbose psql --no-password --user postgres
This question should probably be migrated to serverfault.com.

Resources