Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Neon: Serverless Postgres. We separated storage and compute to offer autoscaling, code-like database branching, and scale to zero.

License

NotificationsYou must be signed in to change notification settings

neondatabase/neon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 theNeon Free Tier to create a serverless Postgres instance. Then connect to it with your preferred Postgres client (psql, dbeaver, etc) or use the onlineSQL Editor. SeeConnect from any application for connection instructions.

Alternatively, compile and run the projectlocally.

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 inSUMMARY.md for more information.

Running a local development environment

Neon can be run on a workstation for small experiments and to test code changes, byfollowing these instructions.

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 \libprotobuf-dev libcurl4-openssl-dev openssl python3-poetry lsof libicu-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 openssl poetry lsof libicu-devel libpq-devel python3-devel \  libffi-devel
  • On Arch based systems, these packages are needed:
pacman -S base-devel readline zlib libseccomp openssl clang \postgresql-libs cmake postgresql protobuf curl lsof

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

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

Installing dependencies on macOS (12.3.1)

  1. Install XCode and dependencies
xcode-select --installbrew install protobuf openssl flex bison icu4c pkg-config m4# add openssl to PATH, required for ed25519 keys generation in neon_localecho 'export PATH="$(brew --prefix openssl)/bin:$PATH"' >> ~/.zshrc

If you get errors about missingm4 you may have to install it manually:

brew install m4brew link --force m4
  1. Install Rust
# recommended approach from https://www.rust-lang.org/tools/installcurl --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-macosbrew install libpqbrew link --force libpq

Rustc version

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

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

rustup users who want to build with another toolchain can use therustup 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 that 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.gitcd 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 logmake -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.gitcd 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 logmake -j`sysctl -n hw.logicalcpu` -s

Dependency installation notes

To run thepsql client, install thepostgresql-client package or modifyPATH andLD_LIBRARY_PATH to includepg_install/bin andpg_install/lib, respectively.

To run the integration tests or Python scripts (not required to use the code), installPython (3.11 or higher), and install the python3 packages using./scripts/pysync (requirespoetry>=1.8) 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 initInitializing pageserver node 1 at'127.0.0.1:64000'in".neon"# start pageserver, safekeeper, and broker for their intercommunication> cargo neon startStarting neon broker at 127.0.0.1:50051.storage_broker started, pid: 2918372Starting pageserver node 1 at'127.0.0.1:64000'in".neon".pageserver started, pid: 2918386Starting 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-defaulttenant 9ef87a5bf0d92544f6fafeeb3239695c successfully created on the pageserverCreated an initial timeline'de200bd42b49cc1814412c7e592dd6e9' at Lsn 0/16B5A50for tenant: 9ef87a5bf0d92544f6fafeeb3239695cSetting tenant 9ef87a5bf0d92544f6fafeeb3239695c as a default one# create postgres compute node> cargo neon endpoint create main# start postgres compute node> cargo neon endpoint start mainStarting new endpoint main (PostgreSQL v14) on timeline de200bd42b49cc1814412c7e592dd6e9 ...Starting postgres at'postgresql://cloud_admin@127.0.0.1:55432/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 -p 55432 -h 127.0.0.1 -U cloud_admin postgrespostgres=# CREATE TABLE t(key int primary key, value text);CREATE TABLEpostgres=# insert into t values(1,1);INSERT 0 1postgres=# 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_checkCreated timeline'b3b863fa45fa9e57e615f9f2d944e601' at Lsn 0/16F9A00for tenant: 9ef87a5bf0d92544f6fafeeb3239695c. Ancestor timeline:'main'# check branches tree> cargo neon timeline list(L) main [de200bd42b49cc1814412c7e592dd6e9](L) ┗━ @0/16F9A00: migration_check [b3b863fa45fa9e57e615f9f2d944e601]# create postgres on that branch> cargo neon endpoint create migration_check --branch-name migration_check# start postgres on that branch> cargo neon endpoint start migration_checkStarting new endpoint migration_check (PostgreSQL v14) on timeline b3b863fa45fa9e57e615f9f2d944e601 ...Starting postgres at'postgresql://cloud_admin@127.0.0.1:55434/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:55434  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 -p 55434 -h 127.0.0.1 -U cloud_admin postgrespostgres=# 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 -p 55432 -h 127.0.0.1 -U cloud_admin postgrespostgres=# select * from t; key| value-----+-------   1| 1(1 row)
  1. If you want to run tests afterwards (see below), you must stop all the running pageserver, safekeeper, and postgres instancesyou have just started. You can terminate them all with one command:
> cargo neon stop

More advanced usages can be found atLocal Development Control Plane (neon_local)).

Handling build failures

If you encounter errors during setting up the initial tenant, it's best to stop everything (cargo neon stop) and remove the.neon directory. Then fix the problems, and start the setup again.

Running tests

Rust unit tests

We are usingcargo-nextest to run the tests in Github Workflows.Some crates do not support running plaincargo test anymore, prefercargo nextest run instead.You can installcargo-nextest withcargo install cargo-nextest.

Integration tests

Ensure your dependencies are installed as describedhere.

git clone --recursive https://github.com/neondatabase/neon.gitCARGO_BUILD_FLAGS="--features=testing" make./scripts/pytest

By default, this runs both debug and release modes, and all supported postgres versions. Whentesting locally, it is convenient to run just one set of permutations, like this:

DEFAULT_PG_VERSION=17 BUILD_TYPE=release ./scripts/pytest

Flamegraphs

You may find yourself in need of flamegraphs for software in this repository.You can useflamegraph-rs or the originalflamegraph.pl. Your choice!

Important

If you're usinglld ormold, you need the--no-rosegment linker argument.It's ageneral thing with Rust / lld / mold, not specific to this repository.Seethis PR for further instructions.

Cleanup

For cleaning up the source tree from build artifacts, runmake clean in the source directory.

For removing every artifact from build and configure steps, runmake distclean, and also consider removing the cargo binaries in thetarget directory, as well as the database in the.neon directory. Note that removing the.neon directory will remove your database, with all data in it. You have been warned!

Documentation

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

To view yourrustdoc documentation in a browser, try runningcargo doc --no-deps --open

See also README files in some source directories, andrustdoc 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

About

Neon: Serverless Postgres. We separated storage and compute to offer autoscaling, code-like database branching, and scale to zero.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

[8]ページ先頭

©2009-2025 Movatter.jp