PostgreSQL installation and running through terminal - postgresql

I'm currently installing postgresql to learn about databases. I'm new in this field so please bear with me. I use Windows 7 Home Premium and installed PostgreSQL under C:/. So it went well without errors. Now I want to create database using the cmd. So I write createdb 'databaseName' under C:/PostgreSQL/10/bin. But then it wants a password. I'm trying to type any text but it doesn't let me.
Now I searched for solutions and I'm in a circus right now. In the tutorial I'm watching, the instructor installed postgres using 'brew' and just installed a PostgreSQL GUI. Then he runs psql 'databaseName' to use psql commands.
Do I need to install postgres using 'scoop' in windows? or it is the same thing as using the installer from the web? I really don't know what to do now. I'm sorry if this sounds stupid for some of you :/
btw, I think the instructor uses Git Bash while I use cmd of windows

Okay, for windows users who installed PostgreSQL using an installer from web, you don't need to use the cmd instead use the SQL Shell provided by the PostgreSQL itself.

Related

Problem running post-install step. Installation may not complete correctly The database cluster initialisation failed

Installing PostgreSQL v12.3 on Windows 10 with Windows x86-64 installer. I can't find a solution anywhere. Installer allows me to click ok and continue installation. I even have access to all the apps that come with Postgres, including the pgAdmin4 app, but I the 'psql' command in my command line doesn't work.
Anyone know how to resolve this?

Fatal Error. application server could not be contacted

I would like to install PostgreSQL on windows 7. Howver I faced one problem when I am going to launch pgAdmin 4. It shows that "Fatal Error. application server could not be contacted." I tried run as Administrator, deleted file pgAdmin in AppData. Deleted python and in my path. Added PostgreAQL in my path. However due to some reason it shows the above proble. I need your help. Thank you in advance
Here is the solution that worked for me on windows 10:
Delete the pgAdmin folder from AppData C:\Users\%USERNAME%\AppData\Roaming\pgAdmin (Note: AppData is a hidden folder),
Search for "Services" with windows search, scroll down to postgres and click on "stop",
Run pgAdmin as Administrator.
Unistall existing postgresql on your computer.This should uninstall the entire applications associated with postgresql including pgadmin4. Go to your start menu and type in "pgadmin4" to show if you still have associated file.If you see any,trace the location and delete it.
You can now re-install a fresh copy of POSTGRESQL from Enterprisedb which will automatically install pgadmin4 for you. The new installation will prompt you to enter new password. Use a password you can remember since you will always need it to access the database.
I uninstalled my python IDLE and then installed the latest python IDLE. When installed it will give you an option if you should allow all programs including python to have full access to the AppData PATH choose yes and the fatal error will disappear

change which psql launches on startup

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

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