change which psql launches on startup - postgresql

I installed brew install postgresql , which was fine and worked well.
I then installed brew install postgresql8 as I wanted to check some postgres 8 specific things.
I then uninstalled postgresql8, however when I restart my mac, and run which psql, it still defaults to
/opt/local/lib/postgresql83/bin/psql
How can I change this back to default to the latest 9.x psql?

The executable which launches is dependent on PATH-variable and which-command makes its checks based on that variable also. The contents of the PATH-variable depend on different things. You can find more info in here for example.
You can launch the right psql by writing the full path on the command line, for example:
~$ /opt/local/lib/postgresql94/bin/psql

Related

PhpStorm in Ubuntu can't detect pd_dump executable on PostgreSQL Export

My environment:
Ubuntu 20.04.3 LTS on Windows 10
-> https://www.microsoft.com/store/productId/9NBLGGH4MSV6
PhpStorm 2022.1 Build #PS-221.5080.224, built on April 13, 2022
My Problem:
I'm trying to export a PostgreSQL database inside the Database tab of PhpStorm.
To execute the export I right click the database in the list and click on the "Export with 'pg_dump'" option. This opens the Export window with all the options and command preview:
Inside of the window I get the error message "Path to executable is wrong" even tho the pg_dump file exists at the given path /usr/bin/pg_dump. This stops me from executing the export.
I have tried to manually install pg_dump in another directory and select it in the PhpStorm Export window, but it still won't detect the executable. The executable itself works fine.
The solution to this problem was to do a sudo apt-get install postgresql-client.
Apparently there is a general problem with the pg_dump executable of the "postgresql-client-common" package:
https://askubuntu.com/questions/501091/command-pg-dump-not-found
After installing the postgresql-client package, everything works fine in PhpStorm as well.
The code is pretty simple there: IDE checks that file exists and is executable, then run /path/to/pg_dump --version command and parse output looking for some keywords. Unfortunately there are no logs which can show exact reason, but I guess the issue that IDE can't get access to the file. Most likely due to WSL. The workaround is to install IDE and unpack PG binaries on Windows, then configure port forwarding to make PG server accessible from host OS.

Issue loading extension in postres after Homebrew MacOS install

I recently installed Postgres 11.3 using Homebrew on MacOSX Mojave. I'd like to extend a database using TimescaleDB, also installed with Homebrew, but get the following error:
tutorial=# CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;
ERROR: could not open extension control file "/Library/PostgreSQL/11/share/postgresql/extension/timescaledb.control": No such file or directory
Looks like the command expects Postgres to be installed in /Library, but brew info postgres says it is located in /usr/local/Cellar/postgresql/11.3. Is there a way I can modify the path the command uses or change where Postgres is installed?
Figured out I had a previous version of postgres which I had not fully uninstalled.
There were a number of postgres processes running in the Activity Monitor even after brew remove postgres. I killed the one with the lowest PID, restart the computer and reinstalled postgres through Homebrew.
I can now extend databases as expected.

Emacs installed with homebrew only works in terminal

I just installed the latest Emacs with homebrew:
brew install emacs --with-cocoa
It installed successfully, but only runs in the terminal. When I installed it on another machine it starts a separate GUI window. Do I need to specify additional flags?
you can add it to your apps just by running the below command:
brew linkapps emacs
Doc on linkapps
Find installed formulae that provide .app-style OS X apps and symlink
them
into /Applications, allowing for easier access
If you're launching it from within the terminal application, you're more than likely running the emacs that ships with OS-X (v22, IIRC).
To launch the homebrew version, I created an alias in bash:
alias emacs='open -a /Applications/Emacs.app --args $1'
Then typing 'emacs' from the terminal launches the homebrew version.
Try this one https://github.com/railwaycat/emacs-mac-port it is not official but much better looking on OSX.
You want aquamacs.
It Just Works.

I installed PostgreSQL on mavericks, but running `which psql` does not do anything. Did it install correctly?

I installed PostgreSQL using the downloadable graphic installer. I'm able to launch pgAdmin which is PostgreSQL's GUI. However, when I run which psql on the terminal, I'm not getting any path (and based on what I read here it should yield a path provided postgres successfully installed).
After looking at this Stackoverflow post, I should have done it via homebrew. Should I uninstall the PostgreSQL that I got via the graphic installer, and re-install using homebrew?
Noob here, and I appreciate your patience.
If you've installed it using Postgres.app, the path to your binary should be under /Applications/Postgres.app/. Try running this at the terminal, you can see on my system it's under /Applications/Postgres.app/Contents/MacOS/bin.
$: find /Applications/Postgres.app/ -name "psql" -print
/Applications/Postgres.app/Contents/MacOS/bin/psql
If you then want to add this to your path variable, you could use this tutorial.

Installed Postgres.app but it won't work

I just installed Postgres.app on my Mac but it won't work properly. I finished the installation and the app icon is on the menu bar and it says it is listening on port 5432, however, that is what happens if I try to run it from the command-line:
~ $ psql
zsh: correct 'psql' to 'sl' [nyae]? n
zsh: command not found: psql
I had previously installed PostgreSQL via Homebrew but removed it before installing Postgres.app. I am running Mac OS X Lion.
I appreciate any help, I really want to have PostgreSQL running on my machine.
The psql binary for Postgres.app is inside the application bundle and you'll have to add the appropriate directory to your PATH. From the fine manual:
Configure your $PATH
Postgres.app includes many command line tools. If you want to use them, you must configure the $PATH variable.
If you are using bash (default shell on OS X), add the following line to ~/.bash_profile:
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
[...]
So adjust your PATH setting in your zsh config files to include the
Contents/Versions/latest/bin
directory inside your Postgres.app bundle.
I'm reading this as of April 2014 and the directory you must include in your path as far as my Postgres app is concerned is slightly different.
I had to include this:
PATH="/Applications/Postgres.app/Contents/Versions/9.3/bin:$PATH"
I can now run psql in my terminal.
On zsh shell you have the modify .zshrc:
PSQL_PATH="/Applications/Postgres.app/Contents/Versions/latest/bin"
PATH="$PATH:$PSQL_PATH"
On prompt:
exec $SHELL
which psql
What you should do is to use /latest instead of version so you dont need to change it again when updating Postgres.
How to: http://postgresapp.com/documentation/cli-tools.html
then run:
. ~/.bash_profile
to reload .bash_profile and update any functions you add.
This might seem stupid, but I'm curious where you installed Postgres.app? As was suggested in mu is too short's answer, the documentation mentions adding /Applications/Postgres.app/Contents/MacOS/bin to your path. However, this requires that you have installed Postgres.app in your /Applications/ folder.
Before trying any of the more complicated solutions you might have found on Stack Overflow, and other resources via Google, you should make sure you've installed Postgres.app to the right place. It may be as simple as moving Postgres.app to /Applications/ since psql will be found in /Applications/Postgres.app before any other places.
Alternatively, you could use whatever path to Postgres.app you would like. So if you want it in your home directory, then you could use export PATH="~/Postgres.app/Contents/MacOS/bin:$PATH".
HTH
I'm a previous Ubuntu user, now in OSX Trying to run the "which sql" and "pg_restore" commands directly from a terminal I opened didn't work. I clicked on the elephant icon and opened a terminal by "Open psql". Once I've quit from the psql console and written the commands in that terminal, they all worked.
On ZSH terminal, before trying the above solutions you have to install Postgres in the first place. While using Hombrew
First, hit,
brew install postgres Then check if it is installed by which psql