Context : Aims : We determine the total dynamical matter density in the solar neighbourhood using the second Gaia data release ( DR2 ) . Methods : The dynamical matter density distribution is inferred in a framework of a Bayesian hierarchical model , which accounts for position and velocity of all individual stars , as well as the full error covariance matrix of astrometric observables , in a joint fit of the vertical velocity distribution and stellar number density distribution . This was done for eight separate data samples , with different cuts in observed absolute magnitude , each containing about 25,000 stars . The model for the total matter density does not rely on any underlying baryonic model , although we assumed that it is symmetrical , smooth , and monotonically decreasing with distance from the mid-plane . Results : We infer a density distribution which is strongly peaked in the region close to the Galactic plane ( \lesssim 60 ~ { } \text { pc } ) , for all eight stellar samples . Assuming a baryonic model and a dark matter halo of constant density , this corresponds to a surplus surface density of approximately 5–9 M _ { \odot } \text { pc } ^ { -2 } . For the Sun ’ s position and vertical velocity with respect to the Galactic plane , we infer Z _ { \odot } = 4.76 \pm 2.27 ~ { } \text { pc } and W _ { \odot } = 7.24 \pm 0.19 ~ { } \text { km } \text { s } ^ { -1 } . Conclusions : These results suggest a surplus of matter close to the Galactic plane , possibly explained by an underestimated density of cold gas . We discuss possible systematic effects that could bias our result , for example unmodelled non-equilibrium effects , and how to account for such effects in future extensions of this work .