How to set default connection parameters for DBLINK on Postgresql - postgresql

I have Postgresql 9.5 installed on Ubuntu and need to use dblink. However I am using port 5433 (set in postgresql.conf) but dblink always defaults to port 5432. I know you can specify the port in the dblink parameters, but this is massive redundancy when I want to use the default port of my instance.
There is a way of telling dblink to use a specific port by default. I know this because I have successfully changed it in the past - but can't for the life of me remember how I did it. I have tried setting the PGPORT environment variable and rebooting. I have tried recreating the extension. I have tried reinstalling postgresql-contrib. None of this has made a difference. I have a feeling that there is some obscure file I edited but can't remember what, where or how.
Any suggestions of how to change the default connection parameters for dblink?

Got it!
It IS done by changing the environment variable, but this is not an environment variable in the sense that a Windows user would understand it (so changing /etc/environment does not work and neither does any other normal nix-style setting of global environment variables).
To change the default connection parameters for dblink you need to add PGPORT=5433 (in my case) to /etc/postgresql/9.5/main/environment. The annoying thing with Ubuntu install of Postgres is that I have at least three versions of all these sorts of files (including pg_HBA.conf and so on). The ones in /etc/... are mostly not read apart from in this case. It's the ones in my data directory (which for space reasons is in a non-default location). So, for anybody else having the same issue check /etc, /var, /your-data-directory.

Related

In PostgreSQL, how to accept *any* password for the user "postgres"?

I'm working on many projects simultaneously, and some have some passwords defined as default, which can vary along projects. I've got postgresql installed on my (Ubuntu) laptop and of course I'm only using it locally for devving.
I know it's horribly insecure, but I don't expose postgres remotely. So to make things easier I would like the postgresql server to accept ANY password it is given for the postgres user. Is there any way that I could do this?
Set trust for all you local connections in pg_hba.conf like e.g
local all all trust
After editing, restart the postgresql service.

How to set postgreSQL to use as buffers more RAM than my computer has?

I have a problem. I am learning PostgreSQL and I work with pgAdmin 4v4. At this point, I am trying to set PostgreSQL to use as buffers more RAM than my computer has. I am thinking of using something like SET shared_buffers TO '256MB' but I am not sure if it is correct. Do you have any ideas?
SET shared_buffers TO '256MB'
This will not work because shared_buffers must be set at server start and cannot be changed later, and this is a command you would run after the server is already running. You would have to put the setting in postgresql.conf, or specify it with the -B option to the "postgres" command.
You could also set it through 'alter system' command, and it would take effect at the next restart. However, you could easily make it a setting that will cause your system to fail to start again (indeed, that appears to be your goal...), at which point you can't use 'alter system' to fix it, and will have to dig into the .conf files.

How to setup a password for PostgreSQL in postgreapp?

I am using postgresapp for the PostgreSQL and without password I was able to connect to the database and perform operations. I am curious to learn about the password. Also I use Postico as Interface. Open to any suggestions.
The default for Postgres.app is to have no password and set trust-level authentication in pg_hba.conf. To change this, you need to do the following:
Alter the IP address and mask for host all all 127.0.0.1/32 trust as needed in pg_hba.conf, and change authentication method from trust to password or md5 (or whatever your requirements are)
Set the password for the desired user(s) with ALTER USER <username> WITH PASSWORD '<password>';
Reload the conf with SELECT pg_reload_conf()
Note your pg_hba.conf file is usually located in ~/Library/Application Support/Postgres/var-12 -- the sure-fire way to know is by querying SHOW data_directory in your psql prompt
Postgres.app is a great way to get Postgres running on macOS in a few minutes. It ships with a default user name and password, and they you're on your own. Postgres.app is a nicely compiled version of Postgres that you can run by double-clicking, you'll need other tools (and knowledge) to take advantage of Postgres. As you'll have noticed, the UI for Postgres.app is pretty much a few buttons to configure a server, and to give you shortcuts to the logs, configuration files, and data.
If you want to use psql (as mentioned), or any of the other command line tools, they're embedded in the application's package. Right-click, open the package, open Contents, open Versions, open the version you use, and look in bin.
If you want a GUI tool, there are many options. Since you say Postgres.app, I'll assume macOS. You've found Postico, SQLPro for Postgres is good, TablePlus is also good. Those tools have fairly uncluttered UIs. If you want or need more features, pgAdmin has a whole lot to offer, and it's free. I end up using Navicat a lot, even though it has a UI that screams "Look Ma! I wrote it in Java!" It gets a lot done. I'd say that day-to-day on macOS, I use SQLPro most. But, really, it's largely a matter of taste. psql is quite powerful, and you'll find no short of help for that.

What is a straightforward way to connect to Postgres.app with dbext (in Vim)?

When I try to connect to my Postgres.app db using dbext, I get the following error:
dbext:PostgreSQL requires a '$HOME/.pgpass' file in order to authenticate. This file is
missing. The binary 'psql' does not accept commandline passwords.
Other programs connect just fine by using a "local" connection. (Postgres.app runs with my userid.)
In vim :!which psql correctly prints /opt/local/bin/psql (which I have symlinked to the one in the Postgres.app bin directory). And Postgres.app is set up to use "local" authentication and there's no clear sense of where a pg_hba.conf file would go (there is no etc directory in the app bundle). Moreover, Postgres.app doesn't have anything in its documentation about changing access configuration.
I've tried using dbext's :DBPromptForBufferParameters directly, as well as #tpope's vim-rails plugin (which returns without comment from dbext setup via :Rdbext.
So what do I do to get dbext to connect using a "local" connection?
Note - I spent a LOT of time trying to figure this out without trying the obvious, thus the post even when I already have the answer. I'm also curious to see if anyone else has a different approach.
It turns out you can just make an empty ~/.pgpass file (restricting read-write permissions to your userid only to avoid warnings). This was counterintuitive for me (since there is in fact no password), but I suppose in retrospect it's obvious I should have tried it.
I'll point this out on the dbext issue tracker.

Install both Interbase and Firebird

Are there any conflicts if both Interbase and Firebird are installed on the same workstation?
Does anyone have any tips or best practices for this?
Interbase uses port 3050 by default. So, you have to choose another number for Firebird server on the same machine. Port number is specified through firebird.conf file. You have to restart Firebird service after changing conf file.
Actually I have four different versions of FB running on my development computer. In this case every instance must use its own port number and have unique instance name given using -n switch of instsvc.
Dont forget to specify custom port number in a connection string. For port 3051 the string will look like:
Server/3051:path_to_db_file
A good link to check
If you change the port for either Firebird or InterBase, then it's OK.