Postgres on a Mac - macos

I am trying to run Postgres on a mac OS 10.10.5.
I installed via Homebrew. I had previously installed by just downloading from the web at some point but I want to use Homebrew across the board so I moved the original to the trash.
I run
brew services start postgres
That works fine. I now see postgres in my activity monitor and can run
sudo lsof -i -n -P | grep TCP
to see
postgres 807 username 5u IPv6 0x3ba11f77231b4ebb 0t0 TCP [::1]:5432 (LISTEN)
postgres 807 username 6u IPv4 0x3ba11f772808980b 0t0 TCP 127.0.0.1:5432 (LISTEN)
I am trying to add a DB and some tables but when I run postgres I get
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.
I removed the following line from my bash_profile
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.4/bin
I restarted the terminal and when I run which postgres I see it is pointing to
/usr/local/bin/postgres
I don't know how to interact with postgres or get the envoirment fixed up.
Any help would be greatly appreciated!

Related

Connecting PostgreSQL installed in docker inside Hyper-V Ubuntu from Windows 10 PgAdmin

I need help in connecting PostgreSQL which is installed in Docker inside HyperV ubuntu 18.4 from Windows 10 PgAdmin. So far I tried the following
Step 1: Install Postgres in Docker (Ubuntu running on Hyper-V)
sudo docker run -p 5432:5432 --name pg_test -e POSTGRES_PASSWORD=admin -d postgres
Step 2: Create a database
docker exec -it pg_test bash
psql -U postgres
create database mytestdb
Step 3: Get the ip address
sudo docker inspect pg_test | grep IPAddress
//returned with 172.17.0.2
Step 4: pg_hba.conf
host all all 0.0.0.0/0 md5
Step 5: When I try to connect from Windows PgAdmin 4, I get this below error -
Note: I have also tried using UBUNTU VM IP address, but no luck
Your's is a case where you are trying to connect to postgres from another subnet, i.e windows subnet to hyper visor subnet if you are not using bridged protocol.
So case 1:
If this is on NAT\HOST and not on bridge then you need to make sure you are able to ping the ubuntu server from windows server.
next is make sure that port is open from ubuntu's end. How do you check that, do a telnet on the port number from windows cmd prompt.
telnet 192.168.0.10 5432
if you are bridged and you can ping ping the server as well, checked that port is opened which is telnet works. You need to make sure that in the postgres.conf file
"listen address" is to "*". which is all.
Again from OS level in ubuntu run the command systemctl stop firewalld to stop firewall and then try to connect. IF this works then you need to open the port in the firewall using this command:
firewall-cmd --permanent --add-port 5432/tcp
I can see from you docker image that 5432 is already opened. This is more of port mapping and firewalld stuff.
You may want to check that pg_hba.conf is not restricted to local. It should not be the case for docker image but you never know.
See: https://www.postgresql.org/docs/9.1/auth-pg-hba-conf.html
Also, there is a typo: POSTGRES_PASSWOR=admin is missing D, it should be POSTGRES_PASSWORD=admin.
You don't need container IP. Since you have mapped container port to host machine (Ubuntu) anyone outsider just needs the Ubuntu machine IP, and on Ubuntu itself you can use localhost.

Can't access docker container on port 80 on OSX

In my current job we have development environment made with docker-compose.
One container is nginx, which provide routing to other containers.
Everything seems fine and work to my colleague on windows and osx. But on my system (osx El Capitan), there is problem with accessing nginx container on port 80.
There is setup of container from docker-compose.yml
nginx:
build: ./dockerbuild/nginx
ports:
- 80:80
links:
- php
volumes_from:
- app
... and more
In ./dockerbuild/nginx there is nothing special, just nginx config as we know it from everywhere.
When I run everyting with docker-compose create and docker-compose start. Then docker ps give me
3b296c1e4775 docker_nginx "nginx -g 'daemon off" About an hour ago Up 47 minutes 0.0.0.0:80->80/tcp, 443/tcp docker_nginx_1
But when I try to access it for example via curl I get error. curl: (7) Failed to connect to localhost port 80: Connection refused
I try to run container with port 81 and everything works fine.
Port is really binded to docker
22:47 $ sudo lsof -i -n -P | grep TCP
...
com.docke 14718 schovi 38u IPv4 0x6e9c93c51ec4b617 0t0 TCP *:80 (LISTEN)
...
Firewall in osx is turned off and I have no other security.
if you are using docker-for-mac:
Accessing by localhost:80 is correct, though you still have to ensure you do not have a local apache/nginx service running. Often leftovers from boxen/homebrew exist binding that port, because thats what developers did back then :)
if you are using dockertoolbox/virtualbox/whatever hypervisor
You will not be able to access it by localhost, by by the docker-machine ip, so write docker-machine ip default and the use http://$ip:80 in your browser
if that does not help
Ensure your nginx container actually does work, so connect to the container: docker exec -i -t <containerid> bash
and then run ps aux nginx or if telnet is installed try to connect to localhost
Solved!
Problem was, that long long time ago I installed pow (super simple automated rails server which run application on app_name.local domain). And this beast left LaunchAgent script which update pf to forward port 80 to pow port.
In my current job we have development environment made with docker-compose.
A privilege to use.
[W]hen I try to access [nginx on port 80] for example via curl I get error.
Given there's nothing from causing you from accessing docker on your host os you should look at the app running inside the container to ensure it's binding to the correct host, e.g. 0.0.0.0 and not localhost.
For example, if you're running Nuxt inside a container with nuxt-ts observe Nuxt will default to localhost thereby causing the container not to connect to the docker network whereas npx nuxt-ts -H 0.0.0.0 gets things squared away with the container's internal server connecting to the ip of the docker network used (verify ip like docker container inspect d8af01990363).

Valet (Laravel): DNS address can not be found

I'm trying out Valet, it looks really nice from what I've heard.
I've been trough the "whole" installation process, Valet is succesfully installed.
But when I cd into my projects file and enter valet park and browse to http://blog.dev, I get "The DNS server address of blog.dev can not be found."
I have no idea what I'm doing wrong. :)
When you run valet install it attempts to install dnsmasq. It requires sudo privileges.
You can check that it's installed and running using
brew services list
You should see something like
dnsmasq started root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
You may however need to tap brew/services first
brew tap homebrew/services
If it's not there, run
brew install dnsmasq
brew services start dnsmasq
Run valet install again to set up dnsmasq and keep an eye out for any errors. What this should do is append a line to the bottom of /usr/local/etc/dnsmasq.conf similar to
conf-file=/Users/{YOURUSER}/.valet/dnsmasq.conf
/Users/{YOURUSER}/.valet/dnsmasq.conf then should contain
address=/.dev/127.0.0.1
Check that your dns server is responding to requests
dig testing.dev #127.0.0.1
You should see a response like
;; ANSWER SECTION:
testing.dev. 0 IN A 127.0.0.1
To actually ensure that your Mac knows that it should resolve *.dev using your local DNS server, it need to be told to do so. Valet also handles this for you but you can check if it's done it's job by doing the following.
Inside the directory /etc/resolver, there should be a file entitled dev with the following contents
nameserver 127.0.0.1
This creates a custom DNS resolver for *.dev and points all requests at your local DNS server.
Restart dnsmasq with either of the following commands and then give it a try again.
// this
brew services restart dnsmasq
// or this
sudo launchctl stop homebrew.mxcl.dnsmasq
sudo launchctl start homebrew.mxcl.dnsmasq
If this is all working, you should be able to ping anything.dev
ping anything.dev
PING anything.dev (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.039 ms
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.081 ms
That ensures the DNS related bits are working.
Ultimately the question is about DNS related problems but as this started off as a here's everything you need to have tried, I'll leave this below. That said, if you're unable to ping something.dev or get an error like "The DNS server address of blog.dev can not be found." as per the OP, it's something above to do with DNS which needs resolving.
Since Caddy serves websites on port 80, you need to ensure that nothing else is running on port 80.
sudo lsof -n -i:80 | grep LISTEN
Ideally this should return caddy if valet is running as expected. You want to see the example below or nothing ideally; nothing because it means we can just start Valet.
caddy 76234 root 3u IPv6 0x4f871f962e84fa95 0t0 TCP *:http (LISTEN)
You may see other webservers, such as Apache or Nginx (and their child processes, _www and nobody) in the example below.
httpd 79 root 4u IPv6 0xf4641199930063c5 0t0 TCP *:http (LISTEN)
httpd 239 _www 4u IPv6 0xf4641199930063c5 0t0 TCP *:http (LISTEN)
nginx 4837 root 6u IPv4 0xf4641199a4e8e915 0t0 TCP 127.0.0.1:http (LISTEN)
nginx 4838 nobody 6u IPv4 0xf4641199a4e8e915 0t0 TCP 127.0.0.1:http (LISTEN)
Assuming you've installed Nginx with homebrew you can run the following to stop it.
brew services stop nginx
OSX ships with Apache installed so you can stop with with the following if it's running.
sudo apachectl stop
At this point you can likely start Valet with valet start and it'll work.
You may get a further error which is caused by PHP being installed without FPM. You can check this using
brew info php70 | grep php70-fpm
Which should yield something along the lines of
The control script is located at /usr/local/opt/php70/sbin/php70-fpm
If it doesn't appear to be installed, use the following.
brew uninstall homebrew/php/php70
brew install homebrew/php/php70 --with-fpm
valet restart
I had the same problem - getting stuck at ping foobar.dev - and fixed it by restarting my Macbook (after valet install). I am sure this is not an exact solution and I reckon there is a way to do this without restarting. Yet, it worked for me. I did not have to do any other steps.
[Edit - Additionally, before restarting I made sure to try the installing with fpm tip, and to follow all brew's suggestions upon installing php70 (tweaking the path, making sure php70 starts on system start. I cannot say whether these things helped, so probably want to try just restarting, first. If it's really just a restart that's required, or some other additional step to properly start services, I think the laravel documentation probably needs some clarification.]
I had the same problem, post installation I got stuck at pinging foo.dev.
I checked for running services.
> brew services list
Name Status User Plist
dnsmasq stopped
nginx stopped
php71 stopped
Started all the three services manually with
> brew services start dnsmasq
> brew services start nginx
> brew services start php71
Ran valet install.
Ping successfully to foo.dev
If you are a Windows user,
Perform the Acrylic Configuration then restart your adapter(Disable and Enable)
http://mayakron.altervista.org/wikibase/show.php?id=AcrylicWindows10Configuration
Worked For Me

Open tcp port 5432 for postgresql mac

I want to open a tcp port (5432) on a mac server to remotely using sql.
I installed psql9.4 using brew.
Initially I tried:
Open /etc/pf.conf in a text editor.
Add a line like this:
pass in proto tcp from any to any port 5432
Save the file.
Load the changes (and test them) with:
sudo pfctl -vnf /etc/pf.conf
Reboot.
I used network utility to check if the port was opened. But no luck.
Then I downloaded IceFloor.
I added custom Rules:
pass on en0 net photo tcp from any to any port =5432 flags S/SA keep state
Also added a new custom service to PFLists Service Database:
service name: PSQL
ports 5432
Still no luck...
Any suggestions?
Thank you

The port 80 in Mac is used

We have to use port 80 for our server. But when I was trying to use it in Mac, it always said that the 80 is used, but I don't know which program uses it.
I searched it in Google, and someone said it's about apache, but I tried, which is not working. I found this: https://gist.github.com/kujohn/7209628 , but seems it's not working visiting our server by IP address.
I really don't know what's going on and how can I find out which program using port 80 and stop it.
Many thanks if anyone can help, I'm new using Mac. Thanks.
To find out what process is using port 80
go to Applications
open utilities.
open Activity Monitor.
click on the Memory tab,
look at the ports and the processes using them. Find port 80 and select it
go to the view on the menu bar and choose Quit process.
This will just kill the process, it will not stop a server instance that is already running from continuing to run.
(Correction: the Ports column shows the number of open ports (and files?), not the port number)
It is not clear if you are using a database management system or not and which one but one method that has worked for me using MAMP is as follows.
stop the server by using sudo apachectl stop command.
then change the port to port 80.
then restart your servers.
type the following in Terminal
sudo lsof -i -n -P | grep TCP
you will get a list - e.g. dropbox listens on 80
you can copy the output to a text editor, etc to search
On Mac ports below 1024 can only be bound by the root user.
Try launching your server as root user (with sudo), or try to use a port above 1024.
You can also try to add root permissions to your user in /etc/sudoers
# root and users in group wheel can run anything on any machine as any user
root ALL = (ALL) ALL
%admin ALL = (ALL) ALL
your_user_here ALL = (ALL) ALL
I was having this issue, apache was disabled via launchctl, but was still tying up port 80 after launch, I could start up apache and it would work, but after unloading it, I couldn't start up anything on port 80. I was using the built in web server for Python as an easy test. It would work on port 81, but not on port 80.
sudo python -m SimpleHTTPServer 80 -- wouldn't work
sudo python -m SimpleHTTPServer 81 -- would work
Here are the symptoms:
$ launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
/System/Library/LaunchDaemons/org.apache.httpd.plist: Could not find specified service
$ sudo lsof -i ':80'
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
Python 3353 root 3u IPv4 0xe455777a82799f05 0t0 TCP *:http (LISTEN)
The fix for me (after way too much searching) was simple:
sudo pfctl -F all
This flushed the packet filter, releasing port 80 (and others I assume 8080, 443, whatever ports apache might be tying up)
After that, and relaunching the python server, it came right up.
Might be Skype that is using port 80. If you have Skype installed and running try to change to a different port in the settings.
Port numbers in the range from 0 to 1023 are classified as 'well-known' and port number 80 is reserved for HTTP. Typically you have servers listening on port 80 to handle HTTP requests.
Source:
http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

Resources