How to execute cross-database queries in a bitnami postgresQL cluster? - postgresql

I try to have a "simple" dbquery with 2 different databases in a postgres bitnami cluster (https://bitnami.com/stack/postgresql-ha/helm) in kubernetes.
I found out, that i problably need DbLink for that (https://www.dbrnd.com/2015/05/postgresql-cross-database-queries-using/), which I tried to install with
Create extension DbLink
There I get the error, that I need superuser rights and my given postgres user (set up within the helm chart with
set {
name = "global.postgresql.username"
value = "myuser"
}
set {
name = "global.postgresql.password"
value = "mypasswort"
}
does not have enough rights.
I tried out the settings for admin:
set {
name = "global.postgresql.adminUsername"
value = "admin_user"
}
set {
name = "global.postgresql.adminPassword"
value = "admin_pw"
}
but it doesnt see to work, at least I can't get a connection with PgAdmin with the given admin credentials. I found out in artefact hub, that the admin cred's are just for the PgPool not for the pgDatabase, whatever that means (I don't know the differece between these both).
So I tried to get a superuse for postgres running with this:
https://dev.to/siumhossain/permission-denied-to-create-extension-extensionnamehint-must-be-superuser-to-create-this-extension-postgres-42mg
So I got into my Minikube Dashboard for my kubernetes cluster and opened a pod of the 3 given pods for my postgresql database and tried to execute
sudo -u postgres psql
This doesnt work because "sudo commant not found".
Now I tried several google solutions for this (e.g. https://unix.stackexchange.com/questions/354928/bash-sudo-command-not-found) but I can't even run
su -
because I dont know the passwort for the user I logged in, which is "I have no name!", which seems a odd user, either given by the minikube dashboard or given by the installed helm chart.
Either way, I can't solve my initial problem nor any of the following problems.
Where ins this row of problems & solution tries am I getting things wrong and how to solve it?

Related

cannot connect to mongo cluster - user is not allowed to do action [getLog] on [admin.]

I have created a user and added my IP to whitelist.
when trying to connect to a cluster through mongo shell, i am required to enter the following line: mongo "mongodb+srv://cluster0.****.mongodb.net/" --username --password
I have filled in credentials for username and password and replaced dbname with my database name(tried using non-existing one as well in case that was the problem). it connects to the shell, but then crashes with the following error:
Error while trying to show server startup warnings: user is not allowed to do action [getLog] on [admin.]
MongoDB Enterprise atlas-7cwf8s-shard-0:PRIMARY>
tried googling and youtubing the issue, but cannot find the match on how to fix it.
Many thanks
That message says that the shell is unable to show you server startup warnings. It's expected in Atlas environment.
Supposing that's your own cluster, then:
Check the user in Atlas > Database Access
Check the MongoDB Roles header in the table.
If it's not atlas Admin, you can't issue this command:
db.adminCommand({getLog:"startupWarnings"})
Or any admin command, which is issued or tested automatically in the connection, hence the error.
Edit MongoDB Roles to the highest privileges (atlas Admin)
But you can still work anyways.
If you're accessing someone else's cluster, then there isn't much to do.

AWS Postgres DB "does not exist" when connecting with PG

I can't seem to connect to my DB instance in AWS. I'm using the pg package and following the examples from the website is not working.
A search for "aws postgres database does not exist" really isn't returning anything helpful. Going through the open/closed issues on the PG github isnt helpful either.
Running $nc <RDS endpoint> <port number> returns a success message so it's definitely there. Every value placed in the Client config is copy/pasted from my DB instance.
I'm starting to wonder if the databases have a different name than what it shows in the "Instances" section of RDS on AWS?
const client = new Client({
host : '<<RDS ENDPOINT>>',
database : '<<RDS NAME>>', // maybe this isnt the real name?
user : '<<username>>',
password : '<<password>>',
port : <<port>>
});
client.connect()
.then(data => {
console.log('connected');
})
.catch(err => {
console.log(err);
})
I ran into this issue as well. It looks like the DB Instance Name and the actual DB name are two different things and even when you add a name when you create your DB, it defaults to 'postgres'. When I put in the name of my DB it gave me the same error. However, when I just put in 'postgres' it worked fine. Try that and see if it works for you.
The initial configuration of RDS instances is quite messy, since the parameter "database name" is only the name of the instance, not the proper name of the database. If you want AWS to create a database at the moment you create the db instance, you have to select "Additional configuration" and explicitly add a parameter called "Initial database name". Check the screenshot I attach here.
Try adding postgres as dbname. It worked for me!
After connecting with postgres as db name, you can type \l to list all database on that PSQL cluster, that will return a bunch of default dbs and also the one you created (the name) so you can connect to it
I ran into the same issue after creating a DB instance on AWS RDS. I wanted to test the connection of my database using PostBird, and I used my actual DB instance name but it could not work.
But I used "postgres in field of DB_name and it worked. That means that my default username was posgres and db_name was also "posgres.
I hope it will help you too.
Try this if the above answer does not work.
Remove the:5439/lab ending so that the Host value ends with: .com

Ansible 2.2 Create Postgresql Database

I am new to ansible (2.2.1) and have started to migrate from our fabric scripts to ansible which I find somewhat better regarding structure. I have run into an issue, it should be pretty straight forward but since I do not know ansible through and through I am not sure how to proceed. I am running this against a vagrant box as of now.
The issue is regarding user privileges and postgres.
Lets say I have this playbook
- hosts: web
become: yes
become_user: root
vars:
dbname: myapp
tasks:
- name: ensure database is created
postgresql_db: name={{dbname}}
I cannot make this simple example work! All dependencies are met. If I do the same thing with mysql this works fine but here I get issues with unable to connect to database: FATAL: Peer authentication failed for user "postgres".
In mysql I use the "root" user with a blank password, which works because I know that user is created upon install with a blank password.
There is a user postgres created when the installation of postgresql is completed so the user exists. And as root I should be able to login by saying I am the postgres user. Am I missing something in how this is done? It works just fine if log into the server and sudo -su postgres && psql.
I also tried to add become_user: postgres by the task I want to run but then I get unprivileged user issues.
Any ideas of what is missing?
Found a few workarounds and a solution, given you are ok with giving away some security (which makes sense, this being an issue just for that reason).
More people having this problem with the new ansible in this github issue thread
https://github.com/ansible/ansible/issues/16048
What I ended up doing was settings allow_world_readable_tmpfiles = True in the ansible.cfg file. Then this is not an issue anymore but you get warnings. I only need this setting for when handling the postgres role, so maybe I'll end up split it up or putting the setting somewhere less global.

Remove all postgresql users/completely delete

As I attempt to create my initial user account on postgresql, I am prompted for my password, though when I enter the correct one I recieve:
createdb: could not connect to database template1: FATAL: password authentication failed for user "thomasmurphy"
I am installing through brew. My thought is that somewhere along the line I've set a password different from my system one. How do I remove all users so I can reset this pass.
I get my permission denied even if I su to postgres. I have gone through every thread on stackoverflow on this issue, and have tried:
*modifying my pg hba_conf
*updating my gems and developer tools
*running brew doctor
*reinstalling postgres
*all the other command line ideas through the thread
My situation seems to not have cropped up before, which convinces me I've set a password at some point that is now tripping all of my attempts. Adding to this theory is that I have a postgres setup on my work computer, also on mavericks, function perfectly.
Note that unless you changed defaults, homebrew installs Postgres with you as the superuser rather than as the postgres user. The issue might be that you're trying to use postgres "as normal" whereas it doesn't need or event want the usual postgres user references.
You see the list of users on the system using cat /etc/passwd, and you can change an arbitrary password by running chpass as root.

Setting postgresql password with Vagrant/Chef-solo

I'm trying my hand at a bit of chef-solo for the first time on a Vagrant box for my open source project apartment so that contributors can more easily get a dev env up and running.
One thing I'm as of yet unable to achieve though is override the default password set by the postgresql recipe from this cookbook
The docs mention setting the json config with something like:
postgresql: {
password: {
postgres: ''
}
}
which I've done here but I can't seem to get it to override the default encrypted password that's set by the recipe.
I'm brand new (as of today) to chef/vagrant so I'm a bit lost as to where I should even look next.
Any help is greatly appreciated.
I cloned your gem and fired up Vagrant (but using a Debian Squeeze image I already downloaded and with all recipes disabled except postgresql and postgresql::server, and using PostgreSQL 8.4 instead of 9.1) and it seems that the empty password was a bad choice, using
postgresql: {
password: {
postgres: 'foo'
}
}
works with the command PGPASSWORD="foo" psql --username=postgres -h localhost so I suspect that the empty password has some problems.