- Run initdb - I'm going to point the data directory (where postgres stores all our data) to /usr/local/var/postgres, I'm also going to set the encoding to utf8. These are sane settings for my use (local web app development) but your usage may require some different settings. Use initdb -help to see the options. $ initdb /usr/local/var/postgres.
- Postgres.app is a simple, native macOS app that runs in the menubar without the need of an installer. Open the app, and you have a PostgreSQL server ready and awaiting new connections. Close the app, and the server shuts down. PostgreSQL can also be installed on macOS using Homebrew. Please see the Homebrew documentation for information on how to install packages.
Launchctl load -w homebrew.mxcl.postgresql.plist. Now when the computer reboots, postgres will automatically startup. Additional Postgres Commands Create a user. Postgres has a shell command called createuser which will create a user for Postgres. Use it right from the OSX terminal command line like this: createuser -pwprompt tunnelsup. Postgres.app is a full-featured PostgreSQL installation packaged as a standard Mac app. It includes everything you need to get started: we’ve even included popular extensions like PostGIS for geo data and plv8 for JavaScript.
You’ve installed PostgreSQL. Now what? I assume you’ve been given a task that uses
psql
and you want to learn the absolute minimum toget the job done.This is both a brief tutorial and a quick reference for the absolute least you need to know about
psql
. I assume you’re familiar with the command line and have a rough idea aboutwhat database administration tasks, but aren’t familiar with how touse psql
to do the basics.Can i stream music with free spotify. The PostgreSQL documentation is incredibly well written and thorough, but frankly, I didn’t know where to start reading. Thisis my answer to that problem.
If you have any complaints or suggestions please let me know by sending your feedback to [email protected].
It shows how to do the following at the
psql
prompt:- Reference pointing to the official PostgreSQL documentation
If you don’t have access to a live PostgreSQL installation at the moment we still have your back.You can follow through the examples and the output is shown as if youdid type everything out.
The psql command line utility
Many administrative tasks can or should be done on your local machine, even though if database lives on the cloud.You can do some of them through a visual user interface, but that’s not covered here. Knowing how to perform these operations on the command line means you can script them,and scripting means you can automate tests, check errors, and do data entry on the command line.
This section isn’t a full cheat sheet for
psql
.It covers the most common operations and shows them roughly in sequence, as you’d use them in a typical work session.Starting and quitting the psql interactive terminal |
---|
Command-line prompts for psql |
Quitting psql |
Opening a connection locally |
Opening a connection remotely |
Looking at the psql prompt |
Getting information about databases |
h Help |
l List databases |
c Connect to a database |
dt Display tables |
d and d+ Display columns (field names) of a table |
du Display user roles |
Creating and using tables and records |
Creating a database |
Creating a table (CREATE TABLE) |
Adding a record (INSERT INTO) |
Inserting several records at once (INSERT INTO) |
Adding only specific fields from a record |
Doing a simple query–get a list of records (SELECT) |
Maintenance and operations |
Maintenance |
What you need to know
Before using this section, you’ll need:
- The user name and password for your PostgreSQL database
- The IP address of your remote instance
Command-line prompts on the operating system
The
$
starting a command line in the examples below represents your operating system prompt. Prompts are configurable so it may well not look like this. On Windows it might look like C:Program FilesPostgreSQL>
but Windows prompts are also configurable.A line starting with
#
represents a comment. Same for everything to the right of a #
. If you accidentally type it or copy and paste it in, don’t worry. Nothing will happen.Using psql
Download album from iphone to mac. You’ll use
psql
(aka the PostgreSQL interactive terminal) most of all because it’s used to create databases and tables, show information about tables, and even to enter information (records) into the database.Quitting pqsql
Before we learn anything else, here’s how to quit
psql
and return to the operating system prompt.You type backslash, the letter q
, and then you press the Enter or return key.This takes you back out to the operating system prompt.
Opening a connection locally
A common case during development is opening a connection to a local database (one on your own machine).Run
psql
with -U
(for user name) followed by the name of the database, postgres
in this example:Opening a connection remotely
To connect your remote PostgreSQL instance from your local machine, use
psql
at your operating system command line.Here’s a typical connection.Here you’d enter the password. In case someone is peering over your shoulder, the characters are hidden. After you’ve entered your information properly you’ll get this message (truncated for clarity):
Looking at the psql prompt
Postgres Mac App
A few things appear, then the
psql
prompt is displayed.The name of the current database appears before the prmopt.![Postgres App Mac Cli Postgres App Mac Cli](/uploads/1/3/3/9/133941251/788412739.jpg)
At this point you’re expected to type commands and parameters into the command line.
psql vs SQL commands
psql
has two different kinds of commands. Mac keyboard cleaner. Those starting with a backslashare for psql
itself, as illustrated by the use of q
to quit.Those starting with valid SQL are of course interactive SQL used tocreate and modify PostgreSQL databases.
Warning: SQL commands end with a semicolon!
One gotcha is that almost all SQL commands you enter into
psql
must end in a semicolon.- For example,suppose you want to remove a table named
sample_property_5
. You’d enter this command:
It’s easy to forget. If you do forget the semicolon, you’ll see this perplexing prompt.Note that a
[
has been inserted before the username portion of the prompt, and anotherprompt appears below it:When you do, just remember to finish it off with that semicolon:
Getting information about databases
These aren’t SQL commands so just press Enter after them. Remember that:
- When there’s more output than fits the screen, it pauses. Press space to continue
- If you want to halt the output, press
q
.
h Help
You’ll get a long list of commands, then output is paused:
- Press space to continue, or
q
to stop the output.
You can get help on a particular item by listing it after the
h
command.- For example, to get help on
DROP TABLE
:
You’ll get help on just tha item: https://skyeyworldwide948.weebly.com/300-series-for-lpc-controller-driver-gigabyte.html.
l List databases
What most people think of as a database (say, a list of customers) is actually a table. A database is a set of tables, information about those tables, information about users and their permissions, and much more. Some of these databases (and the tables within) are updated automatically by PostgreSQL as you use them.
Claire Software has a teriffic app called Go64 (free, donations accepted) that scans the software on your Mac and tells you whether the each app is 64-bit or not. Go64 is fast and it also. Go64 makes it easier to go 64-bit by helping you Take an inventory of the apps on your Mac and see which ones are still 32-bit. Go to a developer's website or search the web for update or upgrade information. Keep track of upgrade costs so you can plan your spending to get all the upgrades you need. https://buyyellow748.weebly.com/mac-app-go-64.html. Macgo offers the first Blu-ray Player for Mac, the best Blu-ray Player software for Windows and iPhone tools like iPhone Cleaner, iPhone Data Recovery, iPhone Explorer, etc.
To get a list of all databases:
You can get info on a single database by following the
l
prompt with its name.- For example, to view information about the
template0
database:
The output would be:
![Postgres App Mac Cli Postgres App Mac Cli](/uploads/1/3/3/9/133941251/984504299.png)
l+ List databases with size, tablespace, and description
To get additional information on the space consumed by database tablesand comments describing those tables, use
l+
:c Connect to a database
To see what’s inside a database, connect to it using
c
followed by the database name. The prompt changes to match the name of the database you’re connecting to.(The one named postgres
is always interesting.) Here we’re connecting to the one namedmarkets
:dt Display tables
- Use
dt
to list all the tables (technically, relations) in the database:
- If you choose a database such as
postgres
there could be many tables.Remember you can pause output by pressing space or halt it by pressingq
.
d and d+ Display columns (field names) of a table
To view the schema of a table, use
d
followed by the name of the table.- To view the schema of a table named
customerpaymentsummary
, enter
To view more detailed information on a table, use
d+
:du Display user roles
- To view all users and their roles, use
du
:
- To view the role of a specific user, pass it after the
du
command.For example, to see the onlytom
role:
Creating a database
Before you add tables, you need to create a database to contain those tables.That’s not done with
psql
, but instead it’s done with createdb
(a separate external command; see the PostgreSQL createdb documentation) at the operating system command line:On success, there is no visual feedback. Thanks, PostgreSQL.
Adding tables and records
Creating a table (CREATE TABLE)
To add a table schema to the database:
And
psql
responds with:For more see
CREATE TABLE
in the PostgreSQL official docs.Adding a record (INSERT INTO)
- Here’s how to add a record, populating every field:
PostgreSQL responds with:
- Try it again and you get a simliar response.
Adding (inserting) several records at once
- You can enter a list of records using this syntax:
Adding only specific (columns) fields from a record
You can add records but specify only selected fields (also known as columns). MySQL will use common sense default values for the rest.
In this example, only the
name
field will be populated. The sku
column is left blank, and the id
column is incremented and inserted.Mac App Store and identified developers: When you try to open a new app and it’s not on the list of identified developers that’s saved within the operating system, the Mac tells you it can’t. Some Mac users say that they can't download programs from other website except Mac App Store, or they may can't be opened the download file. When they click on the download file, it says 'xxx can't be opened because it is from an unidentified developer'.For example. Unable to open com.app.tcc on mac. Error: unable to open database '/Library/Application Support/com.apple.TCC/TCC.db': unable to open database file, and if I try to ls the directory as root I get ls:: Operation not.
Two records are added:
PostgreSQL responds with the number of records inserted:
For more on INSERT, see
INSERT
in the PostgreSQL official docsDoing a simple query–get a list of records (SELECT)
Probably the most common thing you’ll do with a table is to obtain information about itwith the
SELECT
statement. It’s a huge topic- Let’s list all the records in the
product
table:
Postgres App Mac Client
The response:
Note
If your table has mixed case objects such as column names or indexes, you’ll need to enclose them in double quotes. For example, If a column name were
Product
instead of product
your query would need to look like this:For more on SELECT, see the
SELECT
in the PostgreSQL official docs.Maintenance and operations issues
Locate the pg_hba.conf file
Postgres configuration is stored in a file named
pg_hba.conf
somewhere in the file system, butthat location varies widely. The way to find it is to use show hba_file
like this:Avast for apple mac. See below for hot reloading this file while Postgres is running.
Reload the configuration file while Postgres is running
If you make changes to the
pg_hba.conf
Postgres configuration sometimes you need to restart.But you may just choose to reload the pg_hba.conf
configuration file like this:Reference
- PostgreSQL offical docs: Server Administration
psql
, a.k.a the PostgreSQL interactive terminalcreatedb
in the PostgreSQL offical docsCREATE TABLE
in the PostgreSQL official docsINSERT
in the PostgreSQL official docs