• Stars
    star
    11,508
  • Rank 2,736 (Top 0.06 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Neon: Serverless Postgres. We separated storage and compute to offer autoscaling, branching, and bottomless storage.

Neon

Neon

Neon is a serverless open-source alternative to AWS Aurora Postgres. It separates storage and compute and substitutes the PostgreSQL storage layer by redistributing data across a cluster of nodes.

Quick start

Try the Neon Free Tier to create a serverless Postgres instance. Then connect to it with your preferred Postgres client (psql, dbeaver, etc) or use the online SQL Editor. See Connect from any application for connection instructions.

Alternatively, compile and run the project locally.

Architecture overview

A Neon installation consists of compute nodes and the Neon storage engine. Compute nodes are stateless PostgreSQL nodes backed by the Neon storage engine.

The Neon storage engine consists of two major components:

  • Pageserver. Scalable storage backend for the compute nodes.
  • Safekeepers. The safekeepers form a redundant WAL service that received WAL from the compute node, and stores it durably until it has been processed by the pageserver and uploaded to cloud storage.

See developer documentation in SUMMARY.md for more information.

Running local installation

Installing dependencies on Linux

  1. Install build dependencies and other applicable packages
  • On Ubuntu or Debian, this set of packages should be sufficient to build the code:
apt install build-essential libtool libreadline-dev zlib1g-dev flex bison libseccomp-dev \
libssl-dev clang pkg-config libpq-dev cmake postgresql-client protobuf-compiler \
libcurl4-openssl-dev
  • On Fedora, these packages are needed:
dnf install flex bison readline-devel zlib-devel openssl-devel \
  libseccomp-devel perl clang cmake postgresql postgresql-contrib protobuf-compiler \
  protobuf-devel libcurl-devel
  • On Arch based systems, these packages are needed:
pacman -S base-devel readline zlib libseccomp openssl clang \
postgresql-libs cmake postgresql protobuf curl

Building Neon requires 3.15+ version of protoc (protobuf-compiler). If your distribution provides an older version, you can install a newer version from here.

  1. Install Rust
# recommended approach from https://www.rust-lang.org/tools/install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Installing dependencies on macOS (12.3.1)

  1. Install XCode and dependencies
xcode-select --install
brew install protobuf openssl flex bison

# add openssl to PATH, required for ed25519 keys generation in neon_local
echo 'export PATH="$(brew --prefix openssl)/bin:$PATH"' >> ~/.zshrc
  1. Install Rust
# recommended approach from https://www.rust-lang.org/tools/install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
  1. Install PostgreSQL Client
# from https://stackoverflow.com/questions/44654216/correct-way-to-install-psql-without-full-postgres-on-macos
brew install libpq
brew link --force libpq

Rustc version

The project uses rust toolchain file to define the version it's built with in CI for testing and local builds.

This file is automatically picked up by rustup that installs (if absent) and uses the toolchain version pinned in the file.

rustup users who want to build with another toolchain can use rustup override command to set a specific toolchain for the project's directory.

non-rustup users most probably are not getting the same toolchain automatically from the file, so are responsible to manually verify their toolchain matches the version in the file. Newer rustc versions most probably will work fine, yet older ones might not be supported due to some new features used by the project or the crates.

Building on Linux

  1. Build neon and patched postgres
# Note: The path to the neon sources can not contain a space.

git clone --recursive https://github.com/neondatabase/neon.git
cd neon

# The preferred and default is to make a debug build. This will create a
# demonstrably slower build than a release build. For a release build,
# use "BUILD_TYPE=release make -j`nproc` -s"
# Remove -s for the verbose build log

make -j`nproc` -s

Building on OSX

  1. Build neon and patched postgres
# Note: The path to the neon sources can not contain a space.

git clone --recursive https://github.com/neondatabase/neon.git
cd neon

# The preferred and default is to make a debug build. This will create a
# demonstrably slower build than a release build. For a release build,
# use "BUILD_TYPE=release make -j`sysctl -n hw.logicalcpu` -s"
# Remove -s for the verbose build log

make -j`sysctl -n hw.logicalcpu` -s

Dependency installation notes

To run the psql client, install the postgresql-client package or modify PATH and LD_LIBRARY_PATH to include pg_install/bin and pg_install/lib, respectively.

To run the integration tests or Python scripts (not required to use the code), install Python (3.9 or higher), and install python3 packages using ./scripts/pysync (requires poetry>=1.3) in the project directory.

Running neon database

  1. Start pageserver and postgres on top of it (should be called from repo root):
# Create repository in .neon with proper paths to binaries and data
# Later that would be responsibility of a package install script
> cargo neon init
Starting pageserver at '127.0.0.1:64000' in '.neon'.

# start pageserver, safekeeper, and broker for their intercommunication
> cargo neon start
Starting neon broker at 127.0.0.1:50051
storage_broker started, pid: 2918372
Starting pageserver at '127.0.0.1:64000' in '.neon'.
pageserver started, pid: 2918386
Starting safekeeper at '127.0.0.1:5454' in '.neon/safekeepers/sk1'.
safekeeper 1 started, pid: 2918437

# create initial tenant and use it as a default for every future neon_local invocation
> cargo neon tenant create --set-default
tenant 9ef87a5bf0d92544f6fafeeb3239695c successfully created on the pageserver
Created an initial timeline 'de200bd42b49cc1814412c7e592dd6e9' at Lsn 0/16B5A50 for tenant: 9ef87a5bf0d92544f6fafeeb3239695c
Setting tenant 9ef87a5bf0d92544f6fafeeb3239695c as a default one

# start postgres compute node
> cargo neon endpoint start main
Starting new endpoint main (PostgreSQL v14) on timeline de200bd42b49cc1814412c7e592dd6e9 ...
Extracting base backup to create postgres instance: path=.neon/pgdatadirs/tenants/9ef87a5bf0d92544f6fafeeb3239695c/main port=55432
Starting postgres at 'host=127.0.0.1 port=55432 user=cloud_admin dbname=postgres'

# check list of running postgres instances
> cargo neon endpoint list
 ENDPOINT  ADDRESS          TIMELINE                          BRANCH NAME  LSN        STATUS
 main      127.0.0.1:55432  de200bd42b49cc1814412c7e592dd6e9  main         0/16B5BA8  running
  1. Now, it is possible to connect to postgres and run some queries:
> psql -p55432 -h 127.0.0.1 -U cloud_admin postgres
postgres=# CREATE TABLE t(key int primary key, value text);
CREATE TABLE
postgres=# insert into t values(1,1);
INSERT 0 1
postgres=# select * from t;
 key | value
-----+-------
   1 | 1
(1 row)
  1. And create branches and run postgres on them:
# create branch named migration_check
> cargo neon timeline branch --branch-name migration_check
Created timeline 'b3b863fa45fa9e57e615f9f2d944e601' at Lsn 0/16F9A00 for tenant: 9ef87a5bf0d92544f6fafeeb3239695c. Ancestor timeline: 'main'

# check branches tree
> cargo neon timeline list
(L) main [de200bd42b49cc1814412c7e592dd6e9]
(L) ┗━ @0/16F9A00: migration_check [b3b863fa45fa9e57e615f9f2d944e601]

# start postgres on that branch
> cargo neon endpoint start migration_check --branch-name migration_check
Starting new endpoint migration_check (PostgreSQL v14) on timeline b3b863fa45fa9e57e615f9f2d944e601 ...
Extracting base backup to create postgres instance: path=.neon/pgdatadirs/tenants/9ef87a5bf0d92544f6fafeeb3239695c/migration_check port=55433
Starting postgres at 'host=127.0.0.1 port=55433 user=cloud_admin dbname=postgres'

# check the new list of running postgres instances
> cargo neon endpoint list
 ENDPOINT         ADDRESS          TIMELINE                          BRANCH NAME      LSN        STATUS
 main             127.0.0.1:55432  de200bd42b49cc1814412c7e592dd6e9  main             0/16F9A38  running
 migration_check  127.0.0.1:55433  b3b863fa45fa9e57e615f9f2d944e601  migration_check  0/16F9A70  running

# this new postgres instance will have all the data from 'main' postgres,
# but all modifications would not affect data in original postgres
> psql -p55433 -h 127.0.0.1 -U cloud_admin postgres
postgres=# select * from t;
 key | value
-----+-------
   1 | 1
(1 row)

postgres=# insert into t values(2,2);
INSERT 0 1

# check that the new change doesn't affect the 'main' postgres
> psql -p55432 -h 127.0.0.1 -U cloud_admin postgres
postgres=# select * from t;
 key | value
-----+-------
   1 | 1
(1 row)
  1. If you want to run tests afterward (see below), you must stop all the running of the pageserver, safekeeper, and postgres instances you have just started. You can terminate them all with one command:
> cargo neon stop

Running tests

Ensure your dependencies are installed as described here.

git clone --recursive https://github.com/neondatabase/neon.git

CARGO_BUILD_FLAGS="--features=testing" make

./scripts/pytest

Documentation

docs Contains a top-level overview of all available markdown documentation.

To view your rustdoc documentation in a browser, try running cargo doc --no-deps --open

See also README files in some source directories, and rustdoc style documentation comments.

Other resources:

Postgres-specific terms

Due to Neon's very close relation with PostgreSQL internals, numerous specific terms are used. The same applies to certain spelling: i.e. we use MB to denote 1024 * 1024 bytes, while MiB would be technically more correct, it's inconsistent with what PostgreSQL code and its documentation use.

To get more familiar with this aspect, refer to:

Join the development

More Repositories

1

pg_embedding

Hierarchical Navigable Small World (HNSW) algorithm for vector similarity search in PostgreSQL
C
526
star
2

serverless

Connect to Neon PostgreSQL from serverless/worker/edge functions
TypeScript
229
star
3

website

Official docs and website for Neon.
JavaScript
153
star
4

autoscaling

Postgres vertical autoscaling in k8s
Go
126
star
5

yc-idea-matcher

Submit your idea and get a list of similar ideas that YCombinator has invested in in the past.
TypeScript
118
star
6

wsproxy

Go
92
star
7

ask-neon

Chatbot: Search your own knowledge base by semantic similarity
TypeScript
47
star
8

neonctl

Neon CLI tool. The Neon CLI is a command-line interface that lets you manage Neon Serverless Postgres directly from the terminal.
TypeScript
34
star
9

postgres-ai-playground

TypeScript
33
star
10

create-branch-action

GitHub Action to create a new Neon branch
24
star
11

preview-branches-with-vercel

Example project that shows how you can create a branch for every preview deployment on Vercel using GitHub actions
TypeScript
23
star
12

serverless-cfworker-demo

Demo app for @neondatabase/serverless β€”Β details at https://blog.cloudflare.com/neon-postgres-database-from-workers/
HTML
21
star
13

helm-charts

neondatabase helm charts
Smarty
20
star
14

naturesnap

TypeScript
18
star
15

postgres

PostgreSQL in Neon
C
17
star
16

cloudflare-drizzle-neon

Example API using Cloudflare Workers, Drizzle ORM and Neon
TypeScript
16
star
17

neonvm

NeonVM: QEMU-based virtualization API and controller for Kubernetes
Go
16
star
18

ping-thing

Ping a Neon Serverless Postgres database using a Vercel Edge Function to see the journey your request makes.
JavaScript
12
star
19

neon-vercel-kysely

Example use of Neon serverless driver on Vercel Edge Functions with Kysely and kysely-codegen
TypeScript
9
star
20

preview-branches-with-fly

A Neon branch for every Fly Preview app
TypeScript
8
star
21

psql-describe

psql's \d (describe) family of commands ported to JavaScript
JavaScript
7
star
22

delete-branch-action

7
star
23

drizzle-overview

Demo Drizzle ORM, Hono & Neon API
TypeScript
7
star
24

neon-api-python

a Python client for the Neon API
Python
6
star
25

github-automations

Scripts that we use to track issues in github's (beta) projects
TypeScript
5
star
26

tokio-epoll-uring

Use io_uring from vanilla tokio.
Rust
5
star
27

delete-branch-by-name-action

Delete Neon database branch by name
4
star
28

postgres-sample-dbs

A collection of sample Postgres databases for learning, testing, and development.
PLpgSQL
4
star
29

rfcs

4
star
30

neon-branches-visualizer

Visualize your Neon Postgres branches
TypeScript
4
star
31

neon_twitter

TypeScript
3
star
32

neon-vercel-rawsql

Example use of Neon serverless driver on Vercel Edge Functions with raw SQL
TypeScript
3
star
33

zenith.tech

JavaScript
3
star
34

examples

TypeScript
2
star
35

aversion

Rust
2
star
36

neon-hyperdrive

Example use of Neon with Hyperdrive on Cloudflare Workers
TypeScript
2
star
37

meeting-notes

2
star
38

aws-cost-reporter

Create and share AWS Cost and Usage reports in Slack.
Go
2
star
39

mastodon-fly

Dockerfile
2
star
40

devdays2

Neon Developer Days Side Project
JavaScript
2
star
41

zenith-perf-data

Simple collection of zenith performance test runs
HTML
2
star
42

fastapi-apprunner-neon

Create a serverless API using FastAPI, deployed on AWS App Runner and powered by Neon Postgres
Python
2
star
43

lambda-cdk-neon

This is an example API built using AWS Lambda, API Gateway, Secrets Manager and Neon
TypeScript
2
star
44

neon-vercel-http

Example use of Neon serverless driver's experimental HTTP feature on Vercel Edge Functions
TypeScript
1
star
45

neon-vercel-knex

Example use of Neon serverless driver on Vercel Edge Functions with Knex.js
JavaScript
1
star
46

dev-actions

JavaScript
1
star
47

vm-monitor

Rust
1
star
48

restore-neon-branch

Script to restore a Neon branch to a previous state while preserving the same endpoint
TypeScript
1
star
49

neon-google-colab-notebooks

Neon Google Colab Notebooks
Jupyter Notebook
1
star
50

guide-neon-prisma

Example application for Neon Prisma Guide
JavaScript
1
star
51

guide-neon-drizzle

Example application for Neon with Drizzle
TypeScript
1
star
52

neon-postgresql-expert

Input for an OpenAI GPT that can answer questions about Neon database and Postgres
Python
1
star
53

s3-scrubber

Rust
1
star
54

zenith-coverage-data

1
star
55

keycloak-example

TypeScript
1
star
56

.github

Public organization profile
1
star
57

latency-dashboard

TypeScript
1
star
58

neon-vercel-zapatos

Example use of Neon serverless driver on Vercel Edge Functions with Zapatos
TypeScript
1
star
59

rust_wal.experimental

Wrap a database frontend in rust based consensus
Rust
1
star
60

neon-ecto-getting-started-app

Neon Ecto Getting Started
Elixir
1
star
61

rustls-split

Rust
1
star
62

pgvector

C
1
star
63

docker-images

Docker images that helps build and test Neon product
Dockerfile
1
star
64

neon-vector-search-openai-notebooks

Jupyter Notebook for Vector Search with Neon and OpenAI
Jupyter Notebook
1
star
65

reset-branch-action

1
star
66

prisma-vercel-load-test

An app that tests prisma on vercel with vercel postgres
CSS
1
star
67

semicolons

Take a string with multiple Postgres SQL statements, separated by semicolons, and split it into its constituent statements
TypeScript
1
star
68

kube-previews-application

Example project that shows how to create a Neon branch for preview environments deployed on Kubernetes using Argo CD
TypeScript
1
star
69

proxy-bench

Benchmarking tools for Neon's Postgres Proxy
Rust
1
star
70

qovery-lifecycle-job

Shell
1
star