Location of postgresql database on OS X? - macos

I'm sure this has been answered but I cannot seem to find an answer.
I installed postgresql using Homebrew (brew install postgresql) which installed to /usr/local/Cellar/postgresql. Afterwords per the instructions I did this:
If this is your first install, create a database with:
initdb /usr/local/var/postgres
As I understand it, initdb creates a new cluster of databases. So when I did the above is "postgres" the database name and the database itself or just all the necessary bits that all postgresql databases will need?
Where does the actual database end up living? I am new to postgresql and looking for a file or binary that is the database. So, where is the database, and when I create a new one where does it go?

initdb just sets up the directory structure and such that is needed to create new databases. To create a database, use createdb:
SYNOPSIS
createdb [ option... ] [ dbname ] [ description ]
DESCRIPTION
createdb creates a new PostgreSQL database.
Normally, the database user who executes this command becomes the owner
of the new database. However a different owner can be specified via the -O option,
if the executing user has appropriate privileges.
createdb is a wrapper around the SQL command CREATE DATABASE [create_database(7)].
There is no effective difference between creating databases via this utility and
via other methods for accessing the server.
initdb is sort of like creating a new file system on a hard disk: first you create the file system (initdb), then you create a files and directories (createdb).
The actual database files will be under /usr/local/var/postgres after you create the database. So, just create a database and then see what's new or changed under /usr/local/var/postgres. There isn't a single "dbname.db" file or anything like that, each database is a collection of files with names that are only meaningful to the database server.

Run the following query:
SHOW DATA_DIRECTORY;

In my case (not homebrew) the data location is found in this file /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist
<array>
<string>/Users/me/bin/postgres/bin/postmaster</string>
<string>-D/Users/me/data/postgres</string>
</array>

The current behavior of the different installers is documented at https://wiki.postgresql.org/wiki/Installers/Mac_OS_X#Known_Installers. Homebrew does not, as someone commented above, put the data under /Library.

System: MAC OS X 10.9.5
Now (ver. 9.4) this is under the dir called /Library/PostgreSQL
If you go there, open the folder named as the ver. of your PG and then go to the folder data you will find your DB. This is really a set of many-many-many different both binary and text files (most of those are named with long numbers like "92891" or so...
Note, to open the data folder you have to open its properties (right mouse click and select "Get info") and allow you to read this folder.
I wdn't suggest you to open the RW permissions if you aren't familiar with this as any smallest change can affect you whole DB which is would be sad..
Good luck!

Since there are three different libraries in Mac, developers are usually confused with the three scenarios. However, you can find out your PostgreSQL directory with one of the two methods on the Mac Computer.
1. Directory--Absolute Path
1). Scroll up your mouse to the left top of Mac Screen
2). Click the menu "Go"
3). Select the "Go to Folder..."
4). Input the path
/Users/username/Library/Application Support/Postgres
Please change "username" to your name such as "jack" listed as follows.
/Users/jack/Library/Application Support/Postgres
5). Choose the button "Go" to the directory of Postgres.
You will eventually find out Postgres.
2. Find the directory step by step
1). Scroll up your mouse to the left top of Mac Screen.
2). Click the menu "Go".
3). Select the button "Library"
4). Double click the file holder "Application Support".
5). Find out "Postgres" according to the alphabetic order.
Cheers,
Mike

Related

Is there anyway to set the default admin url from oracle apex?

I've installed an oracle apex environment and everything is okay, but my root URL open the admin page and i like to open the application itself. Where i can change it?
For example:
http://my-url.com -> open app
http://my-url.com/apex/admin -> open the admin
Well, if you meant to run Apex (development tool) so that it automatically opens one of applications within that workspace (so that you could develop it further), I don't think that you can do that.
run Apex first (credentials require workspace, username and password)
go to App Builder
choose application (because, one workspace can contain many applications)
work on it
However, if your question is how to actually run desired application without going into Apex (development tool) first, navigating to the application and then running it, then a simple option is to do exactly that:
go to Apex, go to App Builder, run desired application
in browser's address line you'll see something like this:
https://apex.oracle.com/pls/apex/f?p=12488
This is my application whose APP_ID = 12488, stored on online apex.oracle.com, but never mind that - you'd just bookmark that URL and then - whenever you want to run it - choose that bookmark from the list (or the toolbar, depending on where you put it).

Open several SQL Scripts on Toad starup

i am using Toad for Oracle V11.
And i'm already using View>Toad Options> File to execute on new connections to set some parameters when i start a new connection.
Here is also the option File to load on startup, but here i can only select a single file to open on startup. But I always need three different scripts when I open Toad and i don't want to merge them to one file.
Is it somehow possible to always open those three different scripts when i open toad?
You can't do that, as far as I can tell.
See whether creating a project (using the Project Manager; it's the 6th icon in my TOAD 14 toolbar) helps, as you can add folders or folder items (that would be your scripts) to it.

Permission denied when trying to import a CSV file from PGAdmin

I'm using PGAdmin 1.14.3.
When I try to execute an import command:
COPY grad(country_code, postal_code, place_name, admin_name1, admin_code1, admin_name2, admin_code2, admin_name3, admin_code3, latitude, longitude, accuracy)
FROM 'C:\\Users\\denis\\Desktop\\BP2Project\\USA\\US.txt';
I get a
ERROR: could not open file
"C:\Users\denis\Desktop\BP2Project\USA\US.txt" for reading:
Permission denied SQL state: 42501
I did look up other similar questions and none of them solved my issue.
I logged in as user "postgres" who is the superuser. I don't see why I'm missing permissions. I'm on Windows 7.
The permissions article mentioned in the answer by Houari and Flimzy is a good reference material, but a direct answer (the quick fix I used) is:
Right click the folder containing the data file(s) that permission was denied to and then click Properties.
In the Folder's Properties window, select the Security tab.
Click the Edit button.
In the "Permissions for the folder" window that opened, click the Add... button.
Type Everyone into the "Enter the object names to select" text area box.
Click OK and the window will close.
Verify that the default Read & Execute permissions were set to Allow via the check checkbox in the previous window.
As JLB notes, Write permission is needed if dumping from PostgreSQL, opposed to copying into it.
Click OK and the window will close.
Click the Apply button in the Folder Properties window.
Now you can run the SQL COPY statement that needs to access those files.
Once done, return to the Folder's Properties window.
Click the Edit button.
Select the Everyone entry in the "Group or user names:" field.
Click the Remove button.
Click OK on the remaining open windows.
The permissions have now been returned to what they were.
The user Postgres must have read access on the file from which you are about to copy.
Look at this article to see how to modify files' security access on Windows.
Ok, this is how got COPY command working,to export a table to CSV, step by step.
Pls note that I am using pgAdmin 111.
Create the target folder you want to export a table to. E.g C:\myExports
Set a read/write permission on this folder following the steps below :
Right click the folder containing the data file(s) that permission was denied >to and then click Properties.
In the Folder's Properties window, select the Security tab.
Click the Edit button.
In the "Permissions for the folder" window that opened, click the Add... button.
Type Everyone into the "Enter the object names to select" text area box.
Click OK and the window will close.
Verify that the default Read & Execute permissions were set to Allow via the >check checkbox in the previous window.
Click OK and the window will close.
Click the Apply button in the Folder Properties window.
This is the tricky part, inside myExports folder create a blank CSV file with your desired name.E.g employee.csv
Then run the Copy command like this :
copy employee to 'C:\myExports\employee.csv' delimiter ',' csv;
employee is the table name in this example..
Hope this helps.
If you don't want to give permissions to Everyone, you can add permissions to the account that started the service. In the Control Panel - Administrative Tools - Services, copy the account name in the 'Log On' tab. (On my system the account is called 'Network Service'.) Then share the folder with the CSV-file with this user as shown in the answer above.
To solve this problem you must give permission to the CSV file because that CSV file present in a COPY command are read directly by the server, but not client application. So to make this file accessible to a server we must give full read-write permission so that Postgresql user can read and write on that file.
Reference: article showing step by step procedure.
I just ran into this error and even after adding postgres to permissions on the file folder and the file itself, it still didn't work. So, I put the file in a public folder. On Windows this was the path: "C:\Users\Public\Documents\census.csv." It worked!
Responses to this problem on different threads go something like this
1. "Tell me exactly what command you used"
2. "Make sure you have right permissions"
3. "Just use /copy"
I just tried giving permissions to Everyone on the cvs file I am trying to copy from, and it is still giving me the permission denied error. I think this functionality is broken and has been broken for multiple consecutive releases over multiple consecutive versions of Windows.
for me and I've just spent some long hours on this.
I have a central db residing on a HP box running 14.04 postgresql-9.5 pgAdmin3 postgis-2.2, shares are made through a tweeked Samba share. My clients are using a mixture of windows 10.1, 7, 8.1 and I have one ubuntu 14.04 desktop.
I'm working with large tables updating records and normalising data and have built the routines around SQL copy statements from CSV files which were made from the core COPY public.table_1 TO (the share folder I'd set up in Samba https://www.youtube.com/watch?v=ndAYZ0DJ-U4) '/srv/samba/share/[filename].csv'
I can then update the database once the tables have been amended with COPY table_1 from '/srv/samba/share/test.csv' USING DELIMITERS ',' WITH NULL AS '' CSV HEADER; from any of my clients.
The key as far as I have been able to determine is that the clients doing the updating must be superusers, also everything must tie up in terms of users as there are 4 servers working together here Postgresql, Samba, UNIX and WINS
All of my users are registered on each of the servers with the same username and password homogeneity is the main factor.
I had tried for a long time moving things about and trying various naming conventions but in the end it was http://www.postgresql.org/message-id/CFF47E56EA077241B1FFF390344B5FC10ACB1C0C#webmail.begavalley.nsw.gov.au that sorted me out it was like a big switch clicking in. chown 777 on your shares and group management was an important learning curve but., the hours I've spent on this will reap rewards down the line... Loving Ubuntu loving life and loving the spirit of open source but that just might be sleep deprivation kicking in... IT WORKS
I am trying to execute SQL commands directly from a file in psql 14, and landed the same error.
The reason is that "postgres" user is different from the 'admin' or the main user of the operating-system. So, this main user denies "postgres" to access files from its file system.
Although there is a way to bypass it.
Windows lets any user access the files in 'C:\Users\Public' and Linux distros allow files in '/tmp' folder to do the same.
So, whatever files you are trying to access from postgres' terminal, keep the files in
'C:\Users\Public' for Windows
'/tmp' in Ubuntu
Read from the orginal source of this answer
use \copy command from psql instead with this config:
sudo psql -U postgres -d <your-db> -c "\copy <your-query-or-table> TO '<pat-to-save-file>' WITH (FORMAT CSV)"

Create large amount of user accounts in OS X Lion Server's Server App/Server Admin/Workgroup Manager

I'm trying to managing iOS devices by OS X Lion Server on Mac Mini.
Now I need to create more than 100 user accounts in Server App. If there's any way to do this without creating each account one by one? Writing script?
http://manuals.info.apple.com/en_US/UserMgmt_v10.6.pdf
According to this document, the exported file of accounts is a XML file. But I find no where to create or edit this file in a efficient way.
If you are using Open Directory (which you probably should with that amount of users) one option is to use dscl which is probably a little easier to automate. There's a thread at Apple Discussions describing how to add users to a group.
Workgroup Manager (part of the Server Admin Tools package) can import tab-delimited text files with a little work. When you do the import, you'll need to tell it the file's format -- what the record and field delimiters are (generally newline and tab), then what data each field contains. See this video for an example of the process.
If you need to set attributes that aren't in the file, you can either select all of the imported accounts and set the attribute for all of them at once (the video shows doing this for the home directory location), or (if you think of it before doing the import) create a template account with the relevant settings, save it as a preset (there's a pop-up menu at the bottom of WGM's window), then select that preset in the import dialog box.
Try using Passenger http://macinmind.com/?area=app&app=passenger&pg=info
If you have more than 20 users you might want to buy it for $60 or do what I do and group them by 20 users and run it 5 times.

Edit sqlite file from terminal Mac

I can not find any documents where I can open existing sqlite database file that I made from the terminal on Mac. I want to add some additional rows to the existing database. I probably search for the wrong things, so anything that points me in the right direction is much appriciated.
If you want to remain in the Terminal, you can open a sqlite3 database using the command sqlite3 [databasename]. From here, you can select rows or insert new ones using SQL commands. If you prefer a GUI, there are many to choose from, including the free Firefox plugin, sqlite-manager.
Whenever you work with Mac built-in sqlite3 it saves the files in the current folder where your Terminal is and the way you can access them is the reversed story, open sqlite3 while you are at the folder where your database is.
Find and get precompiled binaries for OSX.
Use the command line client.
I realize this is a bit tangential to the question, but it's helpful to be able to find/move hidden files in Finder, because often sqlite DBs will wind up in a hidden folder. See:
http://www.macworld.com/article/1051830/showallfinder.html
The key bit is to enter this in the Terminal, then force Finder to relaunch (via the Apple menu's Force Quit on Lion):
defaults write com.apple.Finder AppleShowAllFiles YES
Change that to NO at the end to toggle it off.

Resources